Imports System.Runtime.InteropServices
Imports SolidEdgePart
Imports SolidEdgeConstants


Public Class Form1
    Dim WithEvents objCmd As SolidEdgeFramework.Command = Nothing
    Dim WithEvents objMouse As SolidEdgeFramework.Mouse = Nothing
    Public objAssyDoc As SolidEdgeAssembly.AssemblyDocument = Nothing
    Public objFrameComponentOcc As SolidEdgeAssembly.Occurrence = Nothing
    Public objCutPartOcc As SolidEdgeAssembly.Occurrence = Nothing
    Public objPlaneToTrimAgainst As Object = Nothing
    Public blnFrameSelected As Boolean = False
    Public blnPlaneSelected As Boolean = False
    Public blnTargetSelected As Boolean = False





    Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        ' Get the type from the Solid Edge ProgID
        objSEType = Type.GetTypeFromProgID("SolidEdge.Application")
        ' Get the type from the Revision Manager ProgID
        objRevManType = Type.GetTypeFromProgID("RevisionManager.Application")



        



    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Me.ListBox1.Items.Clear()

        'Call a generic function used to connect to exist SE application or if not create a new instance of Solid Edge 
        If oConnectToSolidEdge(True, True) Then



        Else
            MessageBox.Show("Could not connect to or start Solid Edge", "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If


    End Sub

    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        Me.ListBox1.Items.Clear()


        Dim objDoc As SolidEdgePart.PartDocument = Nothing

        'Call a generic function used to add solid edge part
        If oConnectToSolidEdge(True, True) Then

            Try
                Do While objSEApp.Documents.Count <> 0
                    objSEApp.ActiveDocument.close(False)
                Loop
                objDoc = oCreateNewSEDocument(objSEApp, "part")
                'objDoc = oCreateNewSEDocument(objSEApp, "sheetmetal")
                'objDoc = oCreateNewSEDocument(objSEApp, "assembly")
                'objDoc = oCreateNewSEDocument(objSEApp, "draft")
                'objDoc = oCreateNewSEDocument(objSEApp, "weldment")
            Catch ex As Exception
                MessageBox.Show("error add a new document " + ex.Message, "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)

            End Try

        Else
            MessageBox.Show("Could not connect to or start Solid Edge", "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If

    End Sub

    Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click

        Me.ListBox1.Items.Clear()


        Dim ObjDoc As SolidEdgeFramework.SolidEdgeDocument = Nothing
        Dim strFilename As String = String.Empty

        'Call a generic function used to connect to exist SE application or if not create a new instance of Solid Edge 
        If oConnectToSolidEdge(True, True) Then
            Try
                strFilename = "C:\_Work\Events\Dev Day SE University 2012\Test Files\Hanger Bracket.par"
                If oIsValidFileName(strFilename) AndAlso oIsSolidEdgeFile(strFilename) Then
                    ObjDoc = objSEApp.Documents.Open(strFilename)
                End If

            Catch ex As Exception
                MessageBox.Show("error " + ex.Message, "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try


        Else
            MessageBox.Show("Could not connect to or start Solid Edge", "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
    End Sub

    Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click

        Me.ListBox1.Items.Clear()

        Dim ObjDoc As SolidEdgeFramework.SolidEdgeDocument = Nothing
        Dim strFilename As String = String.Empty

        'Call a generic function used to connect to exist SE application or if not create a new instance of Solid Edge 
        If oConnectToSolidEdge(True, True) Then
            Try
                strFilename = "C:\_Work\Events\Dev Day SE University 2012\Test Files\Hanger Bracket.par"
                If oIsValidFileName(strFilename) AndAlso oIsSolidEdgeFile(strFilename) Then
                    ObjDoc = objSEApp.Documents.Open(strFilename)


                    'close and save the file
                    If ObjDoc.Path = String.Empty Then  ' The file has never been saved before
                        ObjDoc.SaveAs(NewName:="C:\temp\Drill_Ordered.par")
                        ObjDoc.Close(SaveChanges:=False)
                    Else  ' It is an existing document that has been saved at least once so do not need to provide a path/name
                        ObjDoc.Save()

                        ObjDoc.Close(False)
                    End If

                End If

            Catch ex As Exception
                MessageBox.Show("error " + ex.Message, "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try


        Else
            MessageBox.Show("Could not connect to or start Solid Edge", "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If










    End Sub

    Private Sub Button5_Click(sender As System.Object, e As System.EventArgs) Handles Button5.Click
        Me.ListBox1.Items.Clear()
        Try
            Dim install As New SEInstallDataLib.SEInstallData

            Me.ListBox1.Items.Add("BuildNumber: " + install.GetBuildNumber.ToString)
            Me.ListBox1.Items.Add("Install Path: " + install.GetInstalledPath.ToString)
            Me.ListBox1.Items.Add("Language ID: " + install.GetLanguageID.ToString)
            Me.ListBox1.Items.Add("Major Version: " + install.GetMajorVersion.ToString)
            Me.ListBox1.Items.Add("Minor Version: " + install.GetMinorVersion.ToString)
            Me.ListBox1.Items.Add("Parasolid Major Version: " + install.GetParasolidMajorVersion.ToString)
            Me.ListBox1.Items.Add("Parsolid Minor Version: " + install.GetParasolidMinorVersion.ToString)
            Me.ListBox1.Items.Add("Parsolid Version: " + install.GetParasolidVersion.ToString)
            Me.ListBox1.Items.Add("Service Path Version: " + install.GetServicePackVersion.ToString)
            Me.ListBox1.Items.Add("Version: " + install.GetVersion.ToString)

            oReleaseObject(install)
            oForceGarbageCollection()

        Catch ex As Exception
            MessageBox.Show("error " + ex.Message, "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    Private Sub Button6_Click(sender As System.Object, e As System.EventArgs) Handles Button6.Click
        Me.ListBox1.Items.Clear()


        Dim objDoc As SolidEdgePart.PartDocument = Nothing
        Dim objProfile(0) As SolidEdgePart.Profile
        Dim objLines As SolidEdgeFrameworkSupport.Lines2d = Nothing
        Dim objRelations As SolidEdgeFrameworkSupport.Relations2d = Nothing
        Dim UOM As SolidEdgeFramework.UnitsOfMeasure = Nothing

        'Call a generic function used to add solid edge part
        If oConnectToSolidEdge(True, True) Then

            Try
                Do While objSEApp.Documents.Count <> 0
                    objSEApp.ActiveDocument.close(False)
                Loop
                objDoc = oCreateNewSEDocument(objSEApp, "part")
                objDoc.ModelingMode = SolidEdgePart.ModelingModeConstants.seModelingModeOrdered

                UOM = objDoc.UnitsOfMeasure  ' get the units of measure for the current document.  Later will aide in entering values.
                objProfile(0) = objDoc.ProfileSets.Add.Profiles.Add(objDoc.RefPlanes.Item(1))  ' 1=Top(XY)  2=Right (YZ) 3=Front(XZ)
                objLines = objProfile(0).Lines2d  ' lines 2d (profile line segments) collection object
                With objLines
                    .AddBy2Points(0, 0, 0.04, 0)  '******* ALL numerical values input will be in METERS   .04m=40 mm
                    'if you want to enter values consistent with what you would enter VIA the interactive user interface of Solid Edge
                    'UOM.ParseUnit(SolidEdgeConstants.UnitTypeConstants.igUnitDistance, "40")  will input the value as 40X
                    'where X is the distance unit of measurement of the active file.....  if default metric file then the unit would be mm
                    .AddBy2Points(0.04, 0, 0.04, UOM.ParseUnit(SolidEdgeConstants.UnitTypeConstants.igUnitDistance, "40"))
                    .AddBy2Points(0.04, 0.04, 0, 0.04)
                    .AddBy2Points(0, 0.04, 0, 0)
                End With
                objRelations = objProfile(0).Relations2d  ' Relations 2d (profile constraints) collection object
                With objRelations
                    .AddKeypoint(objLines.Item(1), KeypointIndexConstants.igLineEnd, objLines.Item(2), KeypointIndexConstants.igLineStart)
                    .AddKeypoint(objLines.Item(2), KeypointIndexConstants.igLineEnd, objLines.Item(3), KeypointIndexConstants.igLineStart)
                    .AddKeypoint(objLines.Item(3), KeypointIndexConstants.igLineEnd, objLines.Item(4), KeypointIndexConstants.igLineStart)
                    .AddKeypoint(objLines.Item(4), KeypointIndexConstants.igLineEnd, objLines.Item(1), KeypointIndexConstants.igLineStart)
                End With
                objDoc.Models.AddFiniteExtrudedProtrusion(1, objProfile, SolidEdgePart.FeaturePropertyConstants.igRight, 0.06)
                objProfile(0).Visible = False  'turn off the local profile

                oReleaseObject(objRelations)
                oReleaseObject(objLines)
                oReleaseObject(UOM)
                oReleaseObject(objDoc)
                oForceGarbageCollection()

            Catch ex As Exception
                MessageBox.Show("error " + ex.Message, "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)

            End Try

        Else
            MessageBox.Show("Could not connect to or start Solid Edge", "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If






    End Sub

    Private Sub Button7_Click(sender As System.Object, e As System.EventArgs) Handles Button7.Click
        Dim objDoc As SolidEdgePart.PartDocument = Nothing
        Dim UOM As SolidEdgeFramework.UnitsOfMeasure = Nothing

        If oConnectToSolidEdge(True, True) Then
            Do While objSEApp.Documents.Count <> 0
                objSEApp.ActiveDocument.close(False)
            Loop

            objDoc = oCreateNewSEDocument(objSEApp, "part")
            objDoc.ModelingMode = SolidEdgePart.ModelingModeConstants.seModelingModeOrdered
            UOM = objDoc.UnitsOfMeasure

            Dim objReferencePlanes As SolidEdgePart.RefPlanes = Nothing
            Dim objReferencePlane As SolidEdgePart.RefPlane = Nothing

            objReferencePlanes = objDoc.RefPlanes
            For Each objReferencePlane In objReferencePlanes
                'default reference planes 1=Top(XY) 2=Right (YZ), 3=Front (XZ)
                Dim strReferencePlaneName As String = objReferencePlane.Name
                Dim strReferencePlaneSystemName As String = objReferencePlane.SystemName
                Dim strReferenceplaneEdgebarName As String = objReferencePlane.EdgebarName
            Next

            'Let's draw the profile on the front reference plane
            objReferencePlane = objReferencePlanes.Item(3)


            'now ready to actually draw the profile geometry
            Dim objProfile(0) As SolidEdgePart.Profile
            Dim objProfileCircles As SolidEdgeFrameworkSupport.Circles2d = Nothing

            objProfile(0) = objDoc.ProfileSets.Add.Profiles.Add(objReferencePlane)
            objProfileCircles = objProfile(0).Circles2d
            objProfileCircles.AddByCenterRadius(0.1, 0.1, UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 6.35))

            Dim objDimensions As SolidEdgeFrameworkSupport.Dimensions = Nothing
            Dim objDim1 As SolidEdgeFrameworkSupport.Dimension = Nothing

            objDimensions = objProfile(0).Dimensions
            'place a dimension on the profile circle
            objDim1 = objDimensions.AddCircularDiameter(objProfileCircles.Item(1))
            objDim1.Constraint = True   ' Creates a driving dimension .... setting to false will create a driven dimension
            objDim1.TrackDistance = UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, -40)   'pushes dim away from geometry

            Dim objRefLine As SolidEdgeFrameworkSupport.Line2d = Nothing
            objRefLine = objProfile(0).ProjectRefPlane(objReferencePlanes.Item(2)) 'Create dimensionable object from Reference plane

            Dim objRelns As SolidEdgeFrameworkSupport.Relations2d = Nothing
            ' Define Relations among the Line objects to make the Profile closed
            objRelns = objProfile(0).Relations2d
            ' Adds connect constraint from center of the profile to the midpoint of the reference plane
            Call objRelns.AddKeypoint(objProfileCircles.Item(1), SolidEdgeConstants.KeypointIndexConstants.igCircleCenter, _
                                      objRefLine, SolidEdgeConstants.KeypointIndexConstants.igLineMiddle, )


            ' Check for the Profile Validity
            Dim lngStatus As Long = objProfile(0).End(ValidationCriteria:=SolidEdgePart.ProfileValidationType.igProfileClosed)
            If lngStatus <> 0 Then
                MessageBox.Show("Profile not closed")
            End If

            oReleaseObject(objRelns)
            oReleaseObject(objRefLine)
            oReleaseObject(objDim1)
            oReleaseObject(objReferencePlane)

            'Create the Base Extruded Protrusion Feature
            Dim objModel As SolidEdgePart.Model = Nothing

            objModel = objDoc.Models.AddFiniteExtrudedProtrusion(NumberOfProfiles:=1, _
            ProfileArray:=objProfile, ProfilePlaneSide:= _
            SolidEdgePart.FeaturePropertyConstants.igLeft, ExtrusionDistance:=UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 75))

            objProfile(0).Visible = False

            ' Check the status of Base Feature

            If objModel.ExtrudedProtrusions.Item(1).Status <> SolidEdgePart.FeatureStatusConstants.igFeatureOK Then
                MessageBox.Show("Error in the Creation of Base Protrusion Feature object")
            End If




            'now let's create a lofted cutout
            'need to create RP on the end face of the protrusion just created!
            objReferencePlane = objReferencePlanes.AddParallelByDistance(objModel.ExtrudedProtrusions.Item(1).TopCap, _
                                                                         UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 0), _
                                                                         SolidEdgePart.FeaturePropertyConstants.igLeft, , , True)
            Dim objProfileCS(6) As SolidEdgePart.Profile

            objProfileCS(0) = objDoc.ProfileSets.Add.Profiles.Add(objReferencePlane)
            objProfileCircles = objProfileCS(0).Circles2d
            objProfileCircles.AddByCenterRadius(UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 6.53), _
                                                UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 5.08), _
                                                UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 4.76))

            'Create Dimension
            objDim1 = objDimensions.AddCircularDiameter(objProfileCircles.Item(1))
            objDim1.Constraint = True   ' Creates a driving dimension .... setting to false will create a driven dimension
            objDim1.TrackDistance = UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, -40)   'pushes dim away from geometry


            ' Check for the Profile Validity
            lngStatus = objProfileCS(0).End(ValidationCriteria:=SolidEdgePart.ProfileValidationType.igProfileClosed)
            If lngStatus <> 0 Then
                MessageBox.Show("Profile not closed")
            End If

            oReleaseObject(objDim1)
            oReleaseObject(objDimensions)




            Dim objRefPln As SolidEdgePart.RefPlane = Nothing

            For i = 1 To 5
                objRefPln = objDoc.RefPlanes.AddParallelByDistance(objReferencePlane, _
                Distance:=0.00254 * (i + 1), NormalSide:=SolidEdgeConstants.FeaturePropertyConstants.igLeft)

                objProfileCS(i) = objDoc.ProfileSets.Add.Profiles.Add(pRefPlaneDisp:=objRefPln)
                Call objProfileCS(i).Circles2d.AddByCenterRadius(GetRotatedXCoord(UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 6.53), _
                                                                                  UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 5.08), _
                                                                                  UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitAngle, 180) / 7 * (i + 1)), _
                                                                                  GetRotatedYCoord(UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 6.53), _
                                                                                  UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 5.08), _
                                                                                  UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitAngle, 180) / 7 * (i + 1)), _
                                                                                  UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 4.76))

                ' Check if the Profile is closed
                lngStatus = objProfileCS(i).End(ValidationCriteria:=SolidEdgePart.ProfileValidationType.igProfileClosed)
                If lngStatus <> 0 Then
                    MsgBox("Profile not closed")
                End If
                oReleaseObject(objRefPln)

            Next i



            objRefPln = objDoc.RefPlanes.AddParallelByDistance(ParentPlane:=objReferencePlane, Distance:=UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 20), _
                                                               NormalSide:=SolidEdgePart.FeaturePropertyConstants.igLeft)
            objProfileCS(6) = objDoc.ProfileSets.Add.Profiles.Add(pRefPlaneDisp:=objRefPln)
            objProfileCS(6).Circles2d.AddByCenterRadius(GetRotatedXCoord(UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 6.53), _
                                                                         UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 5.08), _
                                                                         UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitAngle, 180)), _
                                                                         GetRotatedYCoord(UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 6.53), _
                                                                         UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 5.08), _
                                                                         UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitAngle, 180)), _
                                                                         UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 4.76))
            Dim SectionTypes(6) As Long
            Dim OriginArray(6) As Object
            For i = 0 To 6
                SectionTypes(i) = SolidEdgePart.FeaturePropertyConstants.igProfileBasedCrossSection
            Next i
            For i = 0 To 6
                OriginArray(i) = 0
            Next i

            Dim objLoft As SolidEdgePart.LoftedCutout = Nothing
            objLoft = objDoc.Models.Item(1).LoftedCutouts.Add(NumSections:=7, CrossSections:=objProfileCS, _
                                    CrossSectionTypes:=SectionTypes, _
                                    Origins:=OriginArray, _
                                    SegmentMaps:=0, MaterialSide:=SolidEdgePart.FeaturePropertyConstants.igLeft, _
                                    StartExtentType:=SolidEdgePart.FeaturePropertyConstants.igNone, StartExtentDistance:=0, _
                                    StartSurfaceOrRefPlane:=Nothing, EndExtentType:=SolidEdgePart.FeaturePropertyConstants.igNone, _
                                    EndExtentDistance:=0, EndSurfaceOrRefPlane:=Nothing, _
                                    StartTangentType:=SolidEdgePart.FeaturePropertyConstants.igNormal, StartTangentMagnitude:=0.5, _
                                    EndTangentType:=SolidEdgePart.FeaturePropertyConstants.igNormal, EndTangentMagnitude:=0.5)


            'Trun off the profile
            For i = 0 To 6
                objProfileCS(i).Visible = False
            Next i


            If objModel.LoftedCutouts.Item(1).Status <> SolidEdgePart.FeatureStatusConstants.igFeatureOK Then
                MessageBox.Show("Error in the Creation of the lofted cutout")
            End If

            'now pattern the lofted cutout
            Dim FeaturesToPattern(0) As Object
            Dim objPatternProfile As SolidEdgeFrameworkSupport.CircularPatterns2d = Nothing
            Dim objProf As SolidEdgePart.Profile = Nothing
            Const PI = 3.14159265358979

            FeaturesToPattern(0) = objLoft


            objProf = objDoc.ProfileSets.Add.Profiles.Add(objReferencePlane)
            objPatternProfile = objProf.CircularPatterns2d

            Call objPatternProfile.AddByCircle(0, 0, UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 4.76), 0, _
                                               SolidEdgeFrameworkSupport.Geom2dOrientationConstants.igGeom2dOrientClockwise, _
                                               SolidEdgeFrameworkSupport.PatternOffsetTypeConstants.sePatternFixedOffset, 4, PI / 4)


            Call objDoc.Models.Item(1).Patterns.Add(NumberOfFeatures:=1, _
                                FeatureArray:=FeaturesToPattern, Profile:=objProf, PatternType:=SolidEdgePart.PatternTypeConstants.seFastPattern)

            objProf.Visible = False

            If objModel.Patterns.Item(1).Status <> SolidEdgePart.FeatureStatusConstants.igFeatureOK Then
                MessageBox.Show("Error in the Creation of the lofted cutout")
            End If


            'close and save the file
            If objDoc.Path = String.Empty Then  ' The file has never been saved before
                objDoc.SaveAs(NewName:="C:\temp\Drill_Ordered.par")
                objDoc.Close(SaveChanges:=False)
            Else  ' It is an existing document that has been saved at least once so do not need to provide a path/name
                objDoc.Save()
                objDoc.Close(False)
            End If


            oReleaseObject(objRefPln)
            oReleaseObject(objLoft)
            oReleaseObject(objProf)
            oReleaseObject(objPatternProfile)
            oReleaseObject(objDoc)
            oForceGarbageCollection()


        End If
    End Sub

    Public Function GetRotatedXCoord(xval As Double, yval As Double, ang As Double) As Double
        Dim r As Double


        r = Math.Sqrt(xval ^ 2 + yval ^ 2)
        GetRotatedXCoord = r * Math.Cos(ang)

    End Function

    Public Function GetRotatedYCoord(xval As Double, yval As Double, ang As Double) As Double
        Dim r As Double


        r = Math.Sqrt(xval ^ 2 + yval ^ 2)
        GetRotatedYCoord = r * Math.Sin(ang)

    End Function

    Private Sub Button8_Click(sender As System.Object, e As System.EventArgs) Handles Button8.Click
        Dim objDoc As SolidEdgePart.PartDocument = Nothing
        Dim UOM As SolidEdgeFramework.UnitsOfMeasure = Nothing

        If oConnectToSolidEdge(True, True) Then
            Do While objSEApp.Documents.Count <> 0
                objSEApp.ActiveDocument.close(False)
            Loop

            objDoc = oCreateNewSEDocument(objSEApp, "part")
            objDoc.ModelingMode = SolidEdgePart.ModelingModeConstants.seModelingModeSynchronous
            UOM = objDoc.UnitsOfMeasure

            Dim objReferencePlanes As SolidEdgePart.RefPlanes = Nothing
            Dim objReferencePlane As SolidEdgePart.RefPlane = Nothing

            objReferencePlanes = objDoc.RefPlanes
            For Each objReferencePlane In objReferencePlanes
                'default reference planes 1=Top(XY) 2=Right (YZ), 3=Front (XZ)
                Dim strReferencePlaneName As String = objReferencePlane.Name
                Dim strReferencePlaneSystemName As String = objReferencePlane.SystemName
                Dim strReferenceplaneEdgebarName As String = objReferencePlane.EdgebarName
            Next

            'Let's draw the profile on the front reference plane
            objReferencePlane = objReferencePlanes.Item(3)


            'now ready to actually draw the profile geometry
            Dim objProfile(0) As SolidEdgePart.Profile
            Dim objProfileCircles As SolidEdgeFrameworkSupport.Circles2d = Nothing

            objProfile(0) = objDoc.ProfileSets.Add.Profiles.Add(objReferencePlane)
            objProfileCircles = objProfile(0).Circles2d
            objProfileCircles.AddByCenterRadius(0.1, 0.1, UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 6.35))

            Dim objDimensions As SolidEdgeFrameworkSupport.Dimensions = Nothing
            Dim objDim1 As SolidEdgeFrameworkSupport.Dimension = Nothing

            objDimensions = objProfile(0).Dimensions
            'place a dimension on the profile circle
            objDim1 = objDimensions.AddCircularDiameter(objProfileCircles.Item(1))
            objDim1.Constraint = True   ' Creates a driving dimension .... setting to false will create a driven dimension
            objDim1.TrackDistance = UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, -40)   'pushes dim away from geometry

            Dim objRefLine As SolidEdgeFrameworkSupport.Line2d = Nothing
            objRefLine = objProfile(0).ProjectRefPlane(objReferencePlanes.Item(2)) 'Create dimensionable object from Reference plane

            Dim objRelns As SolidEdgeFrameworkSupport.Relations2d = Nothing
            ' Define Relations among the Line objects to make the Profile closed
            objRelns = objProfile(0).Relations2d
            ' Adds connect constraint from center of the profile to the midpoint of the reference plane
            Call objRelns.AddKeypoint(objProfileCircles.Item(1), SolidEdgeConstants.KeypointIndexConstants.igCircleCenter, _
                                      objRefLine, SolidEdgeConstants.KeypointIndexConstants.igLineMiddle, )


            ' Check for the Profile Validity
            Dim lngStatus As Long = objProfile(0).End(ValidationCriteria:=SolidEdgePart.ProfileValidationType.igProfileClosed)
            If lngStatus <> 0 Then
                MessageBox.Show("Profile not closed")
            End If

            oReleaseObject(objRelns)
            oReleaseObject(objRefLine)
            oReleaseObject(objDim1)
            oReleaseObject(objReferencePlane)

            'Create the Base Extruded Protrusion Feature
            Dim objModel As SolidEdgePart.Model = Nothing

            objModel = objDoc.Models.AddFiniteExtrudedProtrusion(NumberOfProfiles:=1, _
            ProfileArray:=objProfile, ProfilePlaneSide:= _
            SolidEdgePart.FeaturePropertyConstants.igLeft, ExtrusionDistance:=UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 75))

            objProfile(0).Visible = False

            ' Check the status of Base Feature

            If objModel.ExtrudedProtrusions.Item(1).Status <> SolidEdgePart.FeatureStatusConstants.igFeatureOK Then
                MessageBox.Show("Error in the Creation of Base Protrusion Feature object")
            End If




            'now let's create a lofted cutout
            'need to create RP on the end face of the protrusion just created!
            'sync model does not have a topcap method
            Dim oFaces As SolidEdgeGeometry.Faces = Nothing
            Dim oFace As SolidEdgeGeometry.Face = Nothing
            oFaces = objModel.ExtrudedProtrusions.Item(1).Faces(SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll)
            'now have to loop through each face with logic to fine the one I need
            Dim dblParam(3) As Double
            Dim dblNormal() As Double = {0}
            ' getting the normal at a point (u=0.5, v=0.5) on a Face
            Const PI = 3.14159265358979
            dblParam(0) = 3 * PI / 2
            dblParam(1) = 0.1
            dblParam(2) = PI / 2
            dblParam(3) = 0.05
            For Each oFace In oFaces
                oFace.GetNormal(NumParams:=2, Params:=dblParam, Normals:=dblNormal)
                'if the normal if the face being process in - Y then that's the one I want
                If dblNormal(1) = -1 Then
                    Exit For
                End If
            Next

            


            'objReferencePlane = objReferencePlanes.AddParallelByDistance(objModel.ExtrudedProtrusions.Item(1).TopCap, _
            '                                                             UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 0), _
            '                                                             SolidEdgePart.FeaturePropertyConstants.igLeft, , , True)

            objReferencePlane = objReferencePlanes.AddParallelByDistance(oFace, _
                                                                        UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 0), _
                                                                        SolidEdgePart.FeaturePropertyConstants.igLeft, , , True)
            oReleaseObject(oFace)
            oReleaseObject(oFaces)


            Dim objProfileCS(6) As SolidEdgePart.Profile

            objProfileCS(0) = objDoc.ProfileSets.Add.Profiles.Add(objReferencePlane)
            objProfileCircles = objProfileCS(0).Circles2d
            objProfileCircles.AddByCenterRadius(UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 6.53), _
                                                UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 5.08), _
                                                UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 4.76))

            'Create Dimension
            objDim1 = objDimensions.AddCircularDiameter(objProfileCircles.Item(1))
            objDim1.Constraint = True   ' Creates a driving dimension .... setting to false will create a driven dimension
            objDim1.TrackDistance = UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, -40)   'pushes dim away from geometry


            ' Check for the Profile Validity
            lngStatus = objProfileCS(0).End(ValidationCriteria:=SolidEdgePart.ProfileValidationType.igProfileClosed)
            If lngStatus <> 0 Then
                MessageBox.Show("Profile not closed")
            End If

            oReleaseObject(objDim1)
            oReleaseObject(objDimensions)




            Dim objRefPln As SolidEdgePart.RefPlane = Nothing

            For i = 1 To 5
                objRefPln = objDoc.RefPlanes.AddParallelByDistance(objReferencePlane, _
                Distance:=0.00254 * (i + 1), NormalSide:=SolidEdgeConstants.FeaturePropertyConstants.igLeft)

                objProfileCS(i) = objDoc.ProfileSets.Add.Profiles.Add(pRefPlaneDisp:=objRefPln)
                Call objProfileCS(i).Circles2d.AddByCenterRadius(GetRotatedXCoord(UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 6.53), _
                                                                                  UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 5.08), _
                                                                                  UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitAngle, 180) / 7 * (i + 1)), _
                                                                                  GetRotatedYCoord(UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 6.53), _
                                                                                  UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 5.08), _
                                                                                  UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitAngle, 180) / 7 * (i + 1)), _
                                                                                  UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 4.76))

                ' Check if the Profile is closed
                lngStatus = objProfileCS(i).End(ValidationCriteria:=SolidEdgePart.ProfileValidationType.igProfileClosed)
                If lngStatus <> 0 Then
                    MsgBox("Profile not closed")
                End If
                oReleaseObject(objRefPln)

            Next i



            objRefPln = objDoc.RefPlanes.AddParallelByDistance(ParentPlane:=objReferencePlane, Distance:=UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 20), _
                                                               NormalSide:=SolidEdgePart.FeaturePropertyConstants.igLeft)
            objProfileCS(6) = objDoc.ProfileSets.Add.Profiles.Add(pRefPlaneDisp:=objRefPln)
            objProfileCS(6).Circles2d.AddByCenterRadius(GetRotatedXCoord(UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 6.53), _
                                                                         UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 5.08), _
                                                                         UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitAngle, 180)), _
                                                                         GetRotatedYCoord(UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 6.53), _
                                                                         UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 5.08), _
                                                                         UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitAngle, 180)), _
                                                                         UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 4.76))
            Dim SectionTypes(6) As Long
            Dim OriginArray(6) As Object
            For i = 0 To 6
                SectionTypes(i) = SolidEdgePart.FeaturePropertyConstants.igProfileBasedCrossSection
            Next i
            For i = 0 To 6
                OriginArray(i) = 0
            Next i

            Dim objLoft As SolidEdgePart.LoftedCutout = Nothing
            objLoft = objDoc.Models.Item(1).LoftedCutouts.Add(NumSections:=7, CrossSections:=objProfileCS, _
                                    CrossSectionTypes:=SectionTypes, _
                                    Origins:=OriginArray, _
                                    SegmentMaps:=0, MaterialSide:=SolidEdgePart.FeaturePropertyConstants.igLeft, _
                                    StartExtentType:=SolidEdgePart.FeaturePropertyConstants.igNone, StartExtentDistance:=0, _
                                    StartSurfaceOrRefPlane:=Nothing, EndExtentType:=SolidEdgePart.FeaturePropertyConstants.igNone, _
                                    EndExtentDistance:=0, EndSurfaceOrRefPlane:=Nothing, _
                                    StartTangentType:=SolidEdgePart.FeaturePropertyConstants.igNormal, StartTangentMagnitude:=0.5, _
                                    EndTangentType:=SolidEdgePart.FeaturePropertyConstants.igNormal, EndTangentMagnitude:=0.5)


            'Trun off the profile
            For i = 0 To 6
                objProfileCS(i).Visible = False
            Next i


            If objModel.LoftedCutouts.Item(1).Status <> SolidEdgePart.FeatureStatusConstants.igFeatureOK Then
                MessageBox.Show("Error in the Creation of the lofted cutout")
            End If

            'now pattern the lofted cutout
            Dim FeaturesToPattern(0) As Object
            Dim objPatternProfile As SolidEdgeFrameworkSupport.CircularPatterns2d = Nothing
            Dim objProf As SolidEdgePart.Profile = Nothing


            FeaturesToPattern(0) = objLoft


            objProf = objDoc.ProfileSets.Add.Profiles.Add(objReferencePlane)
            objPatternProfile = objProf.CircularPatterns2d

            Call objPatternProfile.AddByCircle(0, 0, UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 4.76), 0, _
                                               SolidEdgeFrameworkSupport.Geom2dOrientationConstants.igGeom2dOrientClockwise, _
                                               SolidEdgeFrameworkSupport.PatternOffsetTypeConstants.sePatternFixedOffset, 4, PI / 4)


            'ordered equivalent
            'Call objDoc.Models.Item(1).Patterns.Add(NumberOfFeatures:=1, _
            '                FeatureArray:=FeaturesToPattern, Profile:=objProf, _
            '                PatternType:=SolidEdgePart.PatternTypeConstants.seFastPattern)

            'Synchronous equivalent
            Call objDoc.Models.Item(1).Patterns.AddSync(NumberOfFeatures:=1, _
                            FeatureArray:=FeaturesToPattern, Profile:=objProf)

            objProf.Visible = False

            If objModel.Patterns.Item(1).Status <> SolidEdgePart.FeatureStatusConstants.igFeatureOK Then
                MessageBox.Show("Error in the Creation of the lofted cutout")
            End If


            'close and save the file
            If objDoc.Path = String.Empty Then  ' The file has never been saved before
                objDoc.SaveAs(NewName:="C:\temp\Drill_Synchronous.par")
                objDoc.Close(SaveChanges:=False)
            Else  ' It is an existing document that has been saved at least once so do not need to provide a path/name
                objDoc.Save()
                objDoc.Close(False)
            End If


            oReleaseObject(objRefPln)
            oReleaseObject(objLoft)
            oReleaseObject(objProf)
            oReleaseObject(objPatternProfile)
            oReleaseObject(objDoc)
            oForceGarbageCollection()


        End If
    End Sub

    Private Sub Button9_Click(sender As System.Object, e As System.EventArgs) Handles Button9.Click
        Me.ListBox1.Items.Clear()


        Dim ObjDoc As SolidEdgeFramework.SolidEdgeDocument = Nothing
        Dim strFilename As String = String.Empty = Nothing
        Dim objVariables As SolidEdgeFramework.Variables = Nothing
        Dim objVariable As SolidEdgeFramework.variable = Nothing
        Dim objVariableList As SolidEdgeFramework.VariableList = Nothing
        Dim UOM As SolidEdgeFramework.UnitsOfMeasure = Nothing
        Dim ii As Integer = 0


        'Call a generic function used to connect to exist SE application or if not create a new instance of Solid Edge 
        If oConnectToSolidEdge(True, True) Then
            Try   'ordered part
                strFilename = "C:\_Work\Events\Dev Day SE University 2012\Test Files\Parameters-Ordered.par"
                If oIsValidFileName(strFilename) AndAlso oIsSolidEdgeFile(strFilename) Then
                    ObjDoc = objSEApp.Documents.Open(strFilename)
                End If


                UOM = ObjDoc.UnitsOfMeasure
                objVariables = ObjDoc.Variables  'get the active document variables collection
                objVariableList = objVariables.Query("*")
                For ii = 1 To objVariableList.Count
                    If objVariableList.Item(ii).Name = "PhysicalProperties_Density" Then    'find the exposed variable  "PhysicalProperties_Density"
                        Dim strDensityOfPart As String = CStr(objVariableList.Item(ii).Value)
                        Exit For   ' got the one I want  to exit loop
                    End If
                Next
                oReleaseObject(objVariableList)
                oForceGarbageCollection()

                ' but there's a better way if you know the "name" of the parameter.....  
                objVariableList = objVariables.Query("ID")   'this is a user generated parameter!
                If objVariableList.Count = 1 Then
                    objVariable = objVariableList.Item(1)
                    objVariable.Value = UOM.ParseUnit(SolidEdgeConstants.UnitTypeConstants.igUnitDistance, "175") 'remember must convert to database units
                Else
                    MessageBox.Show("Could not find the parameter I am looking for!", "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                End If
                oReleaseObject(objVariableList)
                oReleaseObject(objVariable)
                oForceGarbageCollection()

                objVariableList = objVariables.Query("RevolvedProtrusion_1_FiniteAngle")    'this is a System generated parameter!
                If objVariableList.Count = 1 Then
                    'objVariable = objVariableList.Item(1)     '  This will not work since dim'ed as a variable object and it is a dimension object!
                    Dim objSystemDimension As SolidEdgeFrameworkSupport.Dimension = Nothing
                    objSystemDimension = objVariableList.Item(1)
                    objSystemDimension.Value = UOM.ParseUnit(SolidEdgeConstants.UnitTypeConstants.igUnitAngle, "90") 'remember must convert to database units
                    oReleaseObject(objSystemDimension)
                Else
                    MessageBox.Show("Could not find the parameter I am looking for!", "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                End If
                oReleaseObject(objVariableList)
                oForceGarbageCollection()

                objVariableList = objVariables.Query("V514")    'this is a System generated parameter!
                If objVariableList.Count = 1 Then
                    'objVariable = objVariableList.Item(1)   '  This will not work since dim'ed as a variable object and it is a dimension object!
                    Dim objSystemDimension As SolidEdgeFrameworkSupport.Dimension = Nothing
                    objSystemDimension = objVariableList.Item(1)
                    objSystemDimension.Value = UOM.ParseUnit(SolidEdgeConstants.UnitTypeConstants.igUnitDistance, "100") 'remember must convert to database units
                Else
                    MessageBox.Show("Could not find the parameter I am looking for!", "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                End If
                oReleaseObject(objVariableList)
                oForceGarbageCollection()


                ObjDoc.Close(False)


            Catch ex As Exception
                MessageBox.Show("error " + ex.Message, "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try

            oReleaseObject(ObjDoc)
            oForceGarbageCollection()

            objSEApp.DoIdle()   'this is important to call when opening and closing documents!

            Try  ' synchronous part
                strFilename = "C:\_Work\Events\Dev Day SE University 2012\Test Files\Parameters-Synchronous.par"
                If oIsValidFileName(strFilename) AndAlso oIsSolidEdgeFile(strFilename) Then
                    ObjDoc = objSEApp.Documents.Open(strFilename)
                End If


                UOM = ObjDoc.UnitsOfMeasure
                objVariables = ObjDoc.Variables  'get the active document variables collection
                objVariableList = objVariables.Query("*")
                For ii = 1 To objVariableList.Count
                    If objVariableList.Item(ii).Name = "PhysicalProperties_Density" Then    'find the exposed variable "Length"
                        Dim strDensityOfPart As String = CStr(objVariableList.Item(ii).Value)
                        Exit For   ' got the one I want  to exit loop
                    End If
                Next
                oReleaseObject(objVariableList)
                oForceGarbageCollection()

                ' but there's a better way if you know the "name" of the parameter.....  
                objVariableList = objVariables.Query("Hole_1_Diameter")   'this is a user generated parameter!
                If objVariableList.Count = 1 Then
                    objVariable = objVariableList.Item(1)
                    objVariable.Value = UOM.ParseUnit(SolidEdgeConstants.UnitTypeConstants.igUnitDistance, "5") 'remember must convert to database units
                Else
                    MessageBox.Show("Could not find the parameter I am looking for!", "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                End If
                oReleaseObject(objVariableList)
                oReleaseObject(objVariable)
                oForceGarbageCollection()


                objVariableList = objVariables.Query("Linear_4")    'this is a System generated parameter!
                If objVariableList.Count = 1 Then
                    'objVariable = objVariableList.Item(1)     '  This will not work since dim'ed as a variable object and it is a dimension object!
                    Dim objSystemDimension As SolidEdgeFrameworkSupport.Dimension = Nothing
                    objSystemDimension = objVariableList.Item(1)

                    ' is it a driving dimensions??   
                    If objSystemDimension.StatusOfDimension = SolidEdgeFrameworkSupport.DimStatusConstants.seDimStatusDriving Then
                        objSystemDimension.Value = UOM.ParseUnit(SolidEdgeConstants.UnitTypeConstants.igUnitDistance, "2") 'remember must convert to database units
                        oReleaseObject(objSystemDimension)
                    End If
                Else
                    MessageBox.Show("Could not find the parameter I am looking for!", "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                End If
                oReleaseObject(objVariableList)
                oForceGarbageCollection()





                objVariableList = objVariables.Query("Linear_7")    'this is a System generated parameter!
                If objVariableList.Count = 1 Then
                    'objVariable = objVariableList.Item(1)     '  This will not work since dim'ed as a variable object and it is a dimension object!
                    Dim objSystemDimension As SolidEdgeFrameworkSupport.Dimension = Nothing
                    objSystemDimension = objVariableList.Item(1)

                    ' is it a driving dimensions??   
                    If objSystemDimension.StatusOfDimension = SolidEdgeFrameworkSupport.DimStatusConstants.seDimStatusDriven Then
                        objSystemDimension.Constraint = True   ' equivalent of locking the dimension in the UI
                        objSystemDimension.SetPMIEditDirection(SolidEdgeFrameworkSupport.PMIEditDirectionConstants.seMoveOriginParent)
                        objSystemDimension.Value = UOM.ParseUnit(SolidEdgeConstants.UnitTypeConstants.igUnitDistance, "12") 'remember must convert to database units
                        objSystemDimension.Constraint = False
                        oReleaseObject(objSystemDimension)
                    End If     
                Else
                    MessageBox.Show("Could not find the parameter I am looking for!", "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                End If
                oReleaseObject(objVariableList)
                oForceGarbageCollection()

                ObjDoc.Close(False)

                oReleaseObject(ObjDoc)
                oForceGarbageCollection()

                objSEApp.DoIdle()   'this is important to call when opening and closing documents!


            Catch ex As Exception
                MessageBox.Show("error " + ex.Message, "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try



        Else
            MessageBox.Show("Could not connect to or start Solid Edge", "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
    End Sub

    Private Sub Button10_Click(sender As System.Object, e As System.EventArgs) Handles Button10.Click
        Me.ListBox1.Items.Clear()


        Dim objDoc As SolidEdgePart.PartDocument = Nothing
        Dim objProperties As SolidEdgeFramework.PropertySets = Nothing
        Dim objProperty As SolidEdgeFramework.Properties = Nothing


        'Call a generic function used to add solid edge part
        If oConnectToSolidEdge(True, True) Then

            Try
                Do While objSEApp.Documents.Count <> 0
                    objSEApp.ActiveDocument.close(False)
                Loop
                objDoc = oCreateNewSEDocument(objSEApp, "part")
                objProperties = objDoc.Properties
                For Each objProperty In objProperties
                    Me.ListBox1.Items.Add("    ")  'add a blank line
                    Me.ListBox1.Items.Add("Property Collection: " & objProperty.Name)
                    For ii = 1 To objProperty.count
                        Try
                            Me.ListBox1.Items.Add(objProperty.item(ii).Name + " : " + objProperty.item(ii).value.ToString)
                        Catch ex As Exception
                            'do not do anything.... 
                        End Try
                    Next
                Next

                oReleaseObject(objProperty)
                oReleaseObject(objProperties)
                oReleaseObject(objDoc)
                oForceGarbageCollection()
           
            Catch ex As Exception
                MessageBox.Show("error add a new document " + ex.Message, "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)

            End Try

        Else
            MessageBox.Show("Could not connect to or start Solid Edge", "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If

    End Sub

    Private Sub Button11_Click(sender As System.Object, e As System.EventArgs) Handles Button11.Click
        Me.ListBox1.Items.Clear()


        Dim ObjDoc As SolidEdgeFramework.SolidEdgeDocument = Nothing
        Dim strFilename As String = String.Empty
        Dim objProperties As SolidEdgeFramework.PropertySets = Nothing



        'Call a generic function used to connect to exist SE application or if not create a new instance of Solid Edge 
        If oConnectToSolidEdge(True, True) Then
            Try
                strFilename = "C:\_Work\Events\Dev Day SE University 2012\Test Files\Hanger Bracket.par"
                If oIsValidFileName(strFilename) AndAlso oIsSolidEdgeFile(strFilename) Then
                    ObjDoc = objSEApp.Documents.Open(strFilename)


                    objProperties = ObjDoc.Properties

                    'For all out-of-the-box properties on the Summary tab of the properties dialog
                    objProperties.Item("SummaryInformation").Item("Title").Value = "Title value written by program"
                    'Replace "Title" in the above line of code with Subject,Author,Manager,Company,Category,Keywords,Comments
                    objProperties.Item("DocumentSummaryInformation").Item("Manager").Value = "Manager value written by program"
                    'Replace "Manager" in the above line of code with Company,Category

                    'For all out-of-the-box properties on the Project tab of the properties dialog
                    objProperties.Item("ProjectInformation").Item("Document Number").Value = "Document Number value written by program"
                    'Replace "Document Number" in the above line of code with Revision Number, Project Name

                    'create customer property of type TEXT
                    objProperties.Item("Custom").Add("GregsCustomTextProperty", "Written by program")
                    'create customer property of type number
                    objProperties.Item("Custom").Add("GregsCustomNumberProperty", 5.0#)
                    'create customer property of type Date
                    objProperties.Item("Custom").Add("GregsCustomDateProperty", #2/6/2007#)
                    'create customer property of type Yes or No
                    objProperties.Item("Custom").Add("GregsCustomYesNOProperty", True)

                    'NOTE:  for custom properties the .add API will either create if property does not yet exist or
                    '       if the proerty already exists the property will simply edit existing property to the value specified

                    objProperties.Save()


                    oReleaseObject(objProperties)
                    oReleaseObject(ObjDoc)
                    oForceGarbageCollection()



                End If

            Catch ex As Exception
                MessageBox.Show("error " + ex.Message, "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try


        Else
            MessageBox.Show("Could not connect to or start Solid Edge", "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
    End Sub

    Private Sub Button12_Click(sender As System.Object, e As System.EventArgs) Handles Button12.Click
        Me.ListBox1.Items.Clear()


        Dim objDoc As SolidEdgeFramework.SolidEdgeDocument = Nothing
        Dim objOccurrences As SolidEdgeAssembly.Occurrences = Nothing
        Dim objOccurrence As SolidEdgeAssembly.Occurrence = Nothing

        Dim OrientationMatrix(0 To 15) As Double     'Must declare the size of the array unlike VB6.0
        Dim strFileName1 As String
        Dim strFileName As String
        Dim UOM As SolidEdgeFramework.UnitsOfMeasure
        strFileName = "C:\_Work\Events\Dev Day SE University 2012\Test Files\chead.par"
        strFileName1 = "C:\_Work\Events\Dev Day SE University 2012\Test Files\splate.par"

        'Call a generic function used to add solid edge part
        If oConnectToSolidEdge(True, True) Then

            Try
                Do While objSEApp.Documents.Count <> 0
                    objSEApp.ActiveDocument.close(False)
                Loop

                objDoc = oCreateNewSEDocument(objSEApp, "assembly")

                objDoc = TryCast(objDoc, SolidEdgeAssembly.AssemblyDocument)
                UOM = objDoc.UnitsOfMeasure
                objOccurrences = objDoc.Occurrences
                If oIsValidFileName(strFileName) Then
                    objOccurrence = objOccurrences.AddWithTransform(strFileName, 0, 0, 0, 0, 0, 0) 'places in the assembly grounded at given orientation
                End If

                If oIsValidFileName(strFileName1) Then
                    OrientationMatrix(0) = -1
                    OrientationMatrix(1) = 0
                    OrientationMatrix(2) = 0
                    OrientationMatrix(3) = 0
                    OrientationMatrix(4) = 0
                    OrientationMatrix(5) = 1
                    OrientationMatrix(6) = 0
                    OrientationMatrix(7) = 0
                    OrientationMatrix(8) = 0
                    OrientationMatrix(9) = 0
                    OrientationMatrix(10) = -1
                    OrientationMatrix(11) = 0
                    OrientationMatrix(12) = 0.02529192779783393
                    OrientationMatrix(13) = -0.015000000000000013
                    OrientationMatrix(14) = 0.018365429602888082
                    OrientationMatrix(15) = 1

                    objOccurrence = objOccurrences.AddWithMatrix(strFileName1, OrientationMatrix)  'places in the assembly grounded using display matrix

                    oReleaseObject(objOccurrence)


                    objOccurrence = objOccurrences.AddByFilename(strFileName1, True)   ' add as simplified  at 0, 0, 0, 0, 0, 0
                    objOccurrence.PutTransform(UOM.ParseUnit(SolidEdgeConstants.UnitTypeConstants.igUnitDistance, "-11.92"), _
                                               UOM.ParseUnit(SolidEdgeConstants.UnitTypeConstants.igUnitDistance, "155"), _
                                               UOM.ParseUnit(SolidEdgeConstants.UnitTypeConstants.igUnitDistance, "18.37"), _
                                               UOM.ParseUnit(SolidEdgeConstants.UnitTypeConstants.igUnitAngle, "180"), 0, 0)   'Move the placed occurrence 



                    oReleaseObject(objOccurrence)
                    oReleaseObject(objOccurrences)




                End If


              



            Catch ex As Exception
                MessageBox.Show("error add a new document " + ex.Message, "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)

            End Try

        Else
            MessageBox.Show("Could not connect to or start Solid Edge", "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If

    End Sub

    Private Sub Button13_Click(sender As System.Object, e As System.EventArgs) Handles Button13.Click
        Me.ListBox1.Items.Clear()


        Dim objDoc As SolidEdgeFramework.SolidEdgeDocument = Nothing
        Dim objOccurrences As SolidEdgeAssembly.Occurrences = Nothing
        Dim objOccurrence As SolidEdgeAssembly.Occurrence = Nothing
        Dim objFirstPart As SolidEdgeAssembly.Occurrence = Nothing
        Dim objFace1 As SolidEdgeGeometry.Face = Nothing
        Dim objRef1 As SolidEdgeFramework.Reference = Nothing
        Dim objFace2 As SolidEdgeGeometry.Face = Nothing
        Dim objRef2 As SolidEdgeFramework.Reference = Nothing
        Dim UVMinRange(2) As Double
        Dim UVMaxRange(2) As Double
        Dim UVPoints(3) As Double
        Dim XYZPoints1(6) As Double
        Dim XYZPoints2(6) As Double
        Dim objRelations3D As SolidEdgeAssembly.Relations3d = Nothing

        Dim strFileName1 As String
        Dim strFileName As String
        Dim UOM As SolidEdgeFramework.UnitsOfMeasure
        strFileName = "C:\_Work\Events\Dev Day SE University 2012\Test Files\chead.par"
        strFileName1 = "C:\_Work\Events\Dev Day SE University 2012\Test Files\splate.par"

        'Call a generic function used to add solid edge part
        If oConnectToSolidEdge(True, True) Then

            Try
                Do While objSEApp.Documents.Count <> 0
                    objSEApp.ActiveDocument.close(False)
                Loop

                objDoc = oCreateNewSEDocument(objSEApp, "assembly")

                objDoc = TryCast(objDoc, SolidEdgeAssembly.AssemblyDocument)
                UOM = objDoc.UnitsOfMeasure
                objOccurrences = objDoc.Occurrences
                If oIsValidFileName(strFileName) Then
                    objFirstPart = objOccurrences.AddWithTransform(strFileName, 0, 0, 0, 0, 0, 0) 'places in the assembly grounded at given orientation
                End If

                If oIsValidFileName(strFileName1) Then
                   
                    objOccurrence = objOccurrences.AddByFilename(strFileName1, False)   ' add as Designed  at 0, 0, 0, 0, 0, 0
                    ' Get the BottomCap on the ExtrudedProtrusion of the Part and a point on it
                    objFace1 = objFirstPart.PartDocument.Models(1).ExtrudedProtrusions(1).TopCap
                    For i = 0 To 1
                        UVPoints(i) = (UVMinRange(i) + UVMaxRange(i)) / 2
                    Next i
                    Call objFace1.GetPointAtParam(1, UVPoints, XYZPoints1)
                    objRef1 = objDoc.CreateReference(objFirstPart, objFace1)  ' Create Reference Object to the above BottomCap


                    ' Get the TopCap on the ExtrudedProtrusion of the Part and a point on it
                    objFace2 = objOccurrence.PartDocument.Models(1).ExtrudedProtrusions(1).TopCap
                    Call objFace2.GetParamRange(UVMinRange, UVMaxRange)
                    For i = 0 To 1
                        UVPoints(i) = (UVMinRange(i) + UVMaxRange(i)) / 2
                    Next i
                    Call objFace2.GetPointAtParam(1, UVPoints, XYZPoints2)
                    objRef2 = objDoc.CreateReference(objOccurrence, objFace2)  ' Create Reference Object to the above BottomCap

                    objRelations3D = objOccurrence.Relations3d
                    If objRelations3D.Count = 1 And objRelations3D.Item(1).type = SolidEdgeConstants.ObjectType.igGroundRelation3d Then
                        objRelations3D.Item(1).delete()    ' delete the ground constraint
                    End If

                    ' Create the Assembly Relation - This automatically invokes the Solver
                    objDoc.Relations3d.AddPlanar(objRef1, objRef2, True, XYZPoints1, XYZPoints2)

                    oReleaseObject(objRef1)
                    oReleaseObject(objRef2)
                    oReleaseObject(objFace1)
                    oReleaseObject(objFace2)
                    oForceGarbageCollection()

                    Dim objModel As SolidEdgePart.Model = Nothing
                    objModel = objFirstPart.PartDocument.Models.item(1)

                    objFace1 = objModel.UserDefinedPatterns.Item(1).Faces(SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryCylinder).item(1)
                    objRef1 = objDoc.CreateReference(Occurrence:=objFirstPart, entity:=objFace1)

                    oReleaseObject(objModel)
                    oForceGarbageCollection()

                    objModel = objOccurrence.PartDocument.Models.item(1)
                    objFace2 = objModel.UserDefinedPatterns.Item(1).Faces(SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryCylinder).item(1)
                    objRef2 = objDoc.CreateReference(objOccurrence, objFace2)


                    Dim objAxial As SolidEdgeAssembly.AxialRelation3d
                    objAxial = objDoc.Relations3d.AddAxial(Axis1:=objRef1, Axis2:=objRef2, NormalsAligned:=True)

                    oReleaseObject(objRef1)
                    oReleaseObject(objRef2)
                    oReleaseObject(objFace1)
                    oReleaseObject(objFace2)
                    oReleaseObject(objAxial)
                    oForceGarbageCollection()

                    objModel = objFirstPart.PartDocument.Models.item(1)

                    objFace1 = objModel.UserDefinedPatterns.Item(1).Faces(SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryCylinder).item(2)
                    objRef1 = objDoc.CreateReference(Occurrence:=objFirstPart, entity:=objFace1)

                    oReleaseObject(objModel)
                    oForceGarbageCollection()

                    objModel = objOccurrence.PartDocument.Models.item(1)
                    objFace2 = objModel.UserDefinedPatterns.Item(1).Faces(SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryCylinder).item(2)
                    objRef2 = objDoc.CreateReference(objOccurrence, objFace2)

                    objAxial = objDoc.Relations3d.AddAxial(Axis1:=objRef1, Axis2:=objRef2, NormalsAligned:=True)

                    'place the other occurrence
                    objOccurrence = objOccurrences.AddByFilename(strFileName1, False)   ' add as Designed  at 0, 0, 0, 0, 0, 0
                    ' Get the BottomCap on the ExtrudedProtrusion of the Part and a point on it
                    objFace1 = objFirstPart.PartDocument.Models(1).ExtrudedProtrusions(1).bottomcap
                    For i = 0 To 1
                        UVPoints(i) = (UVMinRange(i) + UVMaxRange(i)) / 2
                    Next i
                    Call objFace1.GetPointAtParam(1, UVPoints, XYZPoints1)
                    objRef1 = objDoc.CreateReference(objFirstPart, objFace1)  ' Create Reference Object to the above BottomCap


                    ' Get the TopCap on the ExtrudedProtrusion of the Part and a point on it
                    objFace2 = objOccurrence.PartDocument.Models(1).ExtrudedProtrusions(1).TopCap
                    Call objFace2.GetParamRange(UVMinRange, UVMaxRange)
                    For i = 0 To 1
                        UVPoints(i) = (UVMinRange(i) + UVMaxRange(i)) / 2
                    Next i
                    Call objFace2.GetPointAtParam(1, UVPoints, XYZPoints2)
                    objRef2 = objDoc.CreateReference(objOccurrence, objFace2)  ' Create Reference Object to the above BottomCap

                    objRelations3D = objOccurrence.Relations3d
                    If objRelations3D.Count = 1 And objRelations3D.Item(1).type = SolidEdgeConstants.ObjectType.igGroundRelation3d Then
                        objRelations3D.Item(1).delete()    ' delete the ground constraint
                    End If

                    ' Create the Assembly Relation - This automatically invokes the Solver
                    objDoc.Relations3d.AddPlanar(objRef1, objRef2, True, XYZPoints1, XYZPoints2)

                    oReleaseObject(objRef1)
                    oReleaseObject(objRef2)
                    oReleaseObject(objFace1)
                    oReleaseObject(objFace2)
                    oForceGarbageCollection()


                    objModel = objFirstPart.PartDocument.Models.item(1)

                    objFace1 = objModel.UserDefinedPatterns.Item(1).Faces(SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryCylinder).item(1)
                    objRef1 = objDoc.CreateReference(Occurrence:=objFirstPart, entity:=objFace1)

                    oReleaseObject(objModel)
                    oForceGarbageCollection()

                    objModel = objOccurrence.PartDocument.Models.item(1)
                    objFace2 = objModel.UserDefinedPatterns.Item(1).Faces(SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryCylinder).item(2)
                    objRef2 = objDoc.CreateReference(objOccurrence, objFace2)

                    objAxial = objDoc.Relations3d.AddAxial(Axis1:=objRef1, Axis2:=objRef2, NormalsAligned:=True)

                    oReleaseObject(objRef1)
                    oReleaseObject(objRef2)
                    oReleaseObject(objFace1)
                    oReleaseObject(objFace2)
                    oReleaseObject(objAxial)
                    oForceGarbageCollection()

                    objModel = objFirstPart.PartDocument.Models.item(1)

                    objFace1 = objModel.UserDefinedPatterns.Item(1).Faces(SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryCylinder).item(2)
                    objRef1 = objDoc.CreateReference(Occurrence:=objFirstPart, entity:=objFace1)

                    oReleaseObject(objModel)
                    oForceGarbageCollection()

                    objModel = objOccurrence.PartDocument.Models.item(1)
                    objFace2 = objModel.UserDefinedPatterns.Item(1).Faces(SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryCylinder).item(1)
                    objRef2 = objDoc.CreateReference(objOccurrence, objFace2)

                    objAxial = objDoc.Relations3d.AddAxial(Axis1:=objRef1, Axis2:=objRef2, NormalsAligned:=True)

                    oReleaseObject(objRef1)
                    oReleaseObject(objRef2)
                    oReleaseObject(objFace1)
                    oReleaseObject(objFace2)
                    oReleaseObject(objAxial)
                    oReleaseObject(objOccurrence)
                    oReleaseObject(objOccurrences)
                    oForceGarbageCollection()



                End If






            Catch ex As Exception
                MessageBox.Show("error add a new document " + ex.Message, "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)

            End Try

        Else
            MessageBox.Show("Could not connect to or start Solid Edge", "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
    End Sub

    Private Sub Button14_Click(sender As System.Object, e As System.EventArgs) Handles Button14.Click
        Me.ListBox1.Items.Clear()


        Dim ObjDoc As SolidEdgeFramework.SolidEdgeDocument = Nothing
        Dim strFilename As String = String.Empty
        Dim objOccurrences As SolidEdgeAssembly.Occurrences = Nothing
        Dim objOccurrence As SolidEdgeAssembly.Occurrence = Nothing

        'Call a generic function used to connect to exist SE application or if not create a new instance of Solid Edge 
        If oConnectToSolidEdge(True, True) Then
            Try
                strFilename = "C:\_Work\Events\Dev Day SE University 2012\Test Files\CDPlayer\CDPlayer.asm"
                If oIsValidFileName(strFilename) AndAlso oIsSolidEdgeFile(strFilename) Then
                    ObjDoc = objSEApp.Documents.Open(strFilename)

                    ObjDoc = TryCast(ObjDoc, SolidEdgeAssembly.AssemblyDocument)
                    objOccurrences = ObjDoc.Occurrences
                    For Each objOccurrence In objOccurrences
                        Me.ListBox1.Items.Add("Occurence Name : " + objOccurrence.Name + "  is visible in the assembly - " + objOccurrence.Visible.ToString)
                    Next


                End If



            Catch ex As Exception
                MessageBox.Show("error " + ex.Message, "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try


        Else
            MessageBox.Show("Could not connect to or start Solid Edge", "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
    End Sub

    Private Sub Button15_Click(sender As System.Object, e As System.EventArgs) Handles Button15.Click
        Me.ListBox1.Items.Clear()


        Dim ObjDoc As SolidEdgeFramework.SolidEdgeDocument = Nothing
        Dim strFilename As String = String.Empty
        Dim objOccurrences As SolidEdgeAssembly.Occurrences = Nothing
        Dim objOccurrence As SolidEdgeAssembly.Occurrence = Nothing

        'Call a generic function used to connect to exist SE application or if not create a new instance of Solid Edge 
        If oConnectToSolidEdge(True, True) Then
            Try
                strFilename = "C:\_Work\Events\Dev Day SE University 2012\Test Files\CDPlayer\CDPlayer.asm"
                If oIsValidFileName(strFilename) AndAlso oIsSolidEdgeFile(strFilename) Then
                    ObjDoc = objSEApp.Documents.Open(strFilename)

                    ObjDoc = TryCast(ObjDoc, SolidEdgeAssembly.AssemblyDocument)
                    objOccurrences = ObjDoc.Occurrences
                    For Each objOccurrence In objOccurrences
                        ProcessNested(objOccurrence, 1)
                    Next
                End If

                oReleaseObject(objOccurrence)
                oReleaseObject(objOccurrences)
                oReleaseObject(ObjDoc)
                oForceGarbageCollection()

            Catch ex As Exception
                MessageBox.Show("error " + ex.Message, "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try


        Else
            MessageBox.Show("Could not connect to or start Solid Edge", "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
    End Sub
    Public Function ProcessNested(ByVal objOcc As SolidEdgeAssembly.Occurrence, ByVal AssemblyLevel As Integer) As Boolean

        Dim Occ As SolidEdgeAssembly.Occurrence

        Try
            If objOcc.Subassembly = True Then
                Me.ListBox1.Items.Add(Space(3 * AssemblyLevel) + "level: " + AssemblyLevel.ToString + " Sub-Assembly: " + objOcc.Name)
                For Each Occ In objOcc.OccurrenceDocument.Occurrences
                    ProcessNested(Occ, AssemblyLevel + 1)
                Next
            Else
                Me.ListBox1.Items.Add(Space(3 * AssemblyLevel) + "level: " + AssemblyLevel.ToString + "   " + objOcc.Name)
            End If
        Catch ex As Exception
            ProcessNested = False
        End Try


    End Function

    Private Sub Button16_Click(sender As System.Object, e As System.EventArgs) Handles Button16.Click



        Me.ListBox1.Items.Clear()


        Dim ObjDoc As SolidEdgeFramework.SolidEdgeDocument = Nothing
        Dim strFilename As String = String.Empty
        Dim objOccurrences As SolidEdgeAssembly.Occurrences = Nothing
        Dim objOccurrence As SolidEdgeAssembly.Occurrence = Nothing

        'Call a generic function used to connect to exist SE application or if not create a new instance of Solid Edge 
        If oConnectToSolidEdge(True, True) Then
            Try
                strFilename = "C:\_Work\Events\Dev Day SE University 2012\Test Files\Frame.asm"
                If oIsValidFileName(strFilename) AndAlso oIsSolidEdgeFile(strFilename) Then
                    ObjDoc = objSEApp.Documents.Open(strFilename)

                    ObjDoc = TryCast(ObjDoc, SolidEdgeAssembly.AssemblyDocument)

                    objCmd = objSEApp.CreateCommand(SolidEdgeConstants.seCmdFlag.seNoDeactivate)
                    objCmd.Start()
                    objMouse = objCmd.Mouse
                    objMouse.ScaleMode = 1
                    objMouse.WindowTypes = 1
                    objMouse.DynamicsMode = 1
                    objMouse.EnabledMove = True

                    objMouse.ClearLocateFilter()
                    objMouse.AddToLocateFilter(SolidEdgeConstants.seLocateFilterConstants.seLocatePart)
                    objMouse.InterDocumentLocate = True
                    objMouse.LocateMode = SolidEdgeConstants.seLocateModes.seLocateQuickPick
                    objSEApp.StatusBar = "Select frame component to be trimmed."







                    objOccurrences = ObjDoc.Occurrences
                    For Each objOccurrence In objOccurrences
                        ProcessNested(objOccurrence, 1)
                    Next
                End If

                oReleaseObject(objOccurrence)
                oReleaseObject(objOccurrences)
                oReleaseObject(ObjDoc)
                oForceGarbageCollection()

            Catch ex As Exception
                MessageBox.Show("error " + ex.Message, "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try


        Else
            MessageBox.Show("Could not connect to or start Solid Edge", "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If





    End Sub

    Private Sub objMouse_MouseClick(sButton As Short, sShift As Short, dX As Double, dY As Double, dZ As Double, pWindowDispatch As Object, lKeyPointType As Integer, pGraphicDispatch As Object) Handles objMouse.MouseClick
        Dim objSelected As Object = Nothing
        Dim blnDVLineSelected As Boolean = False
        Dim blnAssyOccurrence As Boolean = False


        objSEApp.SetOLEServerBusyTimeout(20000)

        If IsNothing(pGraphicDispatch) = True Then
            objSEApp.StatusBar = "Please select an object!."
            Exit Sub
        End If

        If IsNothing(pGraphicDispatch) = False Then
            objSelected = pGraphicDispatch
        End If

        Try
            If IsNothing(TryCast(objSelected.object, SolidEdgeDraft.DVLine2d)) = False Then
                blnDVLineSelected = True
            End If

            If IsNothing(TryCast(objSelected.object, SolidEdgeGeometry.Face)) = False Then
                blnAssyOccurrence = True
            End If
        Catch ex As Exception
            ' the .object will error out since no present if selected object is an assembly occurrence
            If IsNothing(TryCast(objSelected, SolidEdgeAssembly.Occurrence)) = False Then
                blnAssyOccurrence = True
            End If

        End Try




        If blnDVLineSelected = True Then
            Dim objDraftDoc As SolidEdgeDraft.DraftDocument = Nothing
            Dim objPartDoc As SolidEdgePart.PartDocument
            Dim objEdge As Object = Nothing
            Dim strPartFileName As String = ""
            Dim nDraftBytes As Integer
            Dim bDraftArray As System.Array = System.Array.CreateInstance(GetType(System.Byte), 64)
            Dim objSelectedLineInDraft As SolidEdgeDraft.DVLine2d = Nothing

            objDraftDoc = objSEApp.ActiveDocument
            objSelectedLineInDraft = CType(objSelected.object, SolidEdgeDraft.DVLine2d)
            objSelectedLineInDraft.GetReferenceKey(strPartFileName, bDraftArray, nDraftBytes)


            objPartDoc = objSEApp.Documents.Open(strPartFileName)
            Call objPartDoc.BindKeyToObject(bDraftArray, objEdge)

            Dim StrPlacedOnTheEdgeOfTheModelInPart As String = String.Empty

            Dim objattachedPropertyTable As SolidEdgePart.AttachedPropertyTable = Nothing
            If objPartDoc.QueryByEntity(objEdge).count = 0 Then
                StrPlacedOnTheEdgeOfTheModelInPart = "Attribute not found on corresponding 3D Edge!"
            Else
                objattachedPropertyTable = objPartDoc.QueryByEntity(objEdge).item(1)
                StrPlacedOnTheEdgeOfTheModelInPart = objattachedPropertyTable.AttachedProperties.Item(1).Value
            End If
            
            objPartDoc.Close(False)


            Dim objBalloons As SolidEdgeFrameworkSupport.Balloons = Nothing
            Dim objBalloon1 As SolidEdgeFrameworkSupport.Balloon = Nothing

            objBalloons = objDraftDoc.ActiveSheet.Balloons

            Dim x, y As Double
            Dim oRef As SolidEdgeFramework.Reference = Nothing

            oRef = objSelectedLineInDraft.Reference

            ' Add a vertex to balloon1 leader line... The vertex should be offset slightly from the connect point
            Dim dblVertices1(2) As Double
            dblVertices1(0) = dX - 0.01
            dblVertices1(1) = dY - 0.01


            objBalloon1 = objBalloons.AddByTerminator(oRef, dX, dY, 0, True)
            Call objBalloon1.SetVertices(VertexCount:=1, Vertices:=dblVertices1)
            objBalloon1.BalloonText = StrPlacedOnTheEdgeOfTheModelInPart
            objBalloon1.Leader = True
            objBalloon1.BreakLine = True
            objBalloon1.BreakLineDirection = True
            objBalloon1.BreakLineDistance = 0.01


        End If



        If blnAssyOccurrence = True Then

            If IsNothing(objFrameComponentOcc) = True Then
                Try
                    Dim TempObject As SolidEdgeAssembly.Occurrence
                    TempObject = CType(pGraphicDispatch, SolidEdgeAssembly.Occurrence)

                    ' Dim TempObject As SolidEdgeAssembly.Occurrence = TryCast(pGraphicDispatch, SolidEdgeAssembly.Occurrence)
                    objFrameComponentOcc = TempObject
                    objFrameComponentOcc.Activate = True
                    blnFrameSelected = True
                    objSEApp.StatusBar = "Please select a component to trim the frame against."
                    Exit Sub         
                Catch ex As Exception
                    objSEApp.StatusBar = "Error selecting a frame component to be trimmed.  Try again."
                    Exit Sub
                End Try

            End If


            If IsNothing(objCutPartOcc) = True Then
                Try
                    Dim TempObject1 As SolidEdgeAssembly.Occurrence
                    TempObject1 = CType(pGraphicDispatch, SolidEdgeAssembly.Occurrence)
                    objCutPartOcc = TempObject1
                    objCutPartOcc.Activate = True
                    blnTargetSelected = True
                    objSEApp.StatusBar = "Please select a assembly component to trim the frame against."
                    objMouse.ClearLocateFilter()
                    objMouse.AddToLocateFilter(SolidEdgeConstants.seLocateFilterConstants.seLocatePlane)
                    objSEApp.StatusBar = "Please select a planar surface to trim the frame component against."
                    Exit Sub
                Catch ex As Exception
                    objSEApp.StatusBar = "Error selecting a frame component to be trimmed.  Try again."
                    Exit Sub
                End Try
            End If

            Try
                Dim TempObject As SolidEdgeGeometry.Plane = TryCast(pGraphicDispatch.object, SolidEdgeGeometry.Plane)
                objPlaneToTrimAgainst = pGraphicDispatch.object
                blnPlaneSelected = True
                objMouse.ClearLocateFilter()
            Catch ex As Exception
                objSEApp.StatusBar = "Error selecting a planar surface to trim the frame component against.  Try again."
                Exit Sub
            End Try

            If blnFrameSelected = True And blnPlaneSelected = True And blnTargetSelected = True Then
                objCmd.Done = True
                objSEApp.StatusBar = "  "
                Process()
            End If
        End If

    End Sub

    Public Sub Process()


        Dim objAssemblyFeatureCutouts As SolidEdgeAssembly.AssemblyFeaturesExtrudedCutouts = Nothing
        Dim objAssemblyFeatureCutout As SolidEdgeAssembly.AssemblyFeaturesExtrudedCutout = Nothing
        'first need to check interference of frame and plane to see if the frame needs to be extended so the cutout will work.

        '******* Added because of .NET
        Try
            OleMessageFilter.Register()
        Catch ex As Exception
            'PrintLine("Error registering message filter.")
        End Try
        '******* Added because of .NET

        Try
            'first need to check interference of frame and plane to see if the frame needs to be extended so the cutout will work.

            'store the occurrence in the assembly to be cut( the frame member selected)
            Dim oArrayOfScopeParts(1) As Object
            oArrayOfScopeParts(0) = objFrameComponentOcc
            oArrayOfScopeParts(1) = objCutPartOcc

            'get assembly feature cutout collection
            objAssemblyFeatureCutouts = objSEApp.ActiveDocument.AssemblyFeatures.AssemblyFeaturesExtrudedCutouts


            'now create the profile
            Dim objAsmRefPlanes As SolidEdgeAssembly.AsmRefPlanes = Nothing
            Dim ObjRefPlane As SolidEdgeAssembly.AsmRefPlane = Nothing

            objAsmRefPlanes = objSEApp.ActiveDocument.AsmRefPlanes
            'Dim objPartToCut As SolidEdgeAssembly.Occurrence = Nothing
            Dim oRefPlaneFace As Object = objSEApp.ActiveDocument.CreateReference(objCutPartOcc, objPlaneToTrimAgainst)


            'this is the RP when projected onto the frame body will serve as the profile to slice off the end
            ObjRefPlane = objAsmRefPlanes.AddParallelByDistance(oRefPlaneFace, 0, , , , False)
            oReleaseObject(oRefPlaneFace)

            Dim ObjAssyLayout As SolidEdgeAssembly.Layout = Nothing
            Dim ObjAssyLayouts As SolidEdgeAssembly.Layouts = Nothing

            ObjAssyLayouts = objSEApp.ActiveDocument.Layouts
            ObjAssyLayout = ObjAssyLayouts.Add(ObjRefPlane)
            Dim objProfile As SolidEdgePart.Profile = Nothing
            Dim Profiles(1) As Object
            Dim objObjCircle As SolidEdgeFrameworkSupport.Circle2d = Nothing

            objProfile = ObjAssyLayout.Profile

            Dim dblRadius As Double = 0.1

            dblRadius = Math.Sqrt(objPlaneToTrimAgainst.area / 3.14159)
            dblRadius = dblRadius + 2 * dblRadius

            objObjCircle = objProfile.Circles2d.AddByCenterRadius(x:=0, y:=0, Radius:=dblRadius)




            Dim ExtendSide As SolidEdgeConstants.FeaturePropertyConstants
            Dim KeyPointFlags As SolidEdgeConstants.KeyPointExtentConstants

            ExtendSide = SolidEdgeConstants.FeaturePropertyConstants.igLeft
            KeyPointFlags = SolidEdgeConstants.KeyPointExtentConstants.igTangentNormal

            Profiles.SetValue(objProfile, 0)
            Profiles.SetValue(objProfile, 1)

            objAssemblyFeatureCutout = objAssemblyFeatureCutouts.Add(1, oArrayOfScopeParts, 1, Profiles, SolidEdgePart.FeaturePropertyConstants.igThroughAll, _
                                           SolidEdgeConstants.FeaturePropertyConstants.igLeft, SolidEdgeConstants.FeaturePropertyConstants.igLeft, Nothing, Nothing, KeyPointFlags, Nothing, Nothing)


            objProfile.visible = False

            oReleaseObject(objObjCircle)
            oReleaseObject(objProfile)
            oReleaseObject(ObjAssyLayout)
            oReleaseObject(ObjAssyLayouts)
            oReleaseObject(ObjRefPlane)
            oReleaseObject(ObjRefPlane)
            oReleaseObject(objAsmRefPlanes)
            oReleaseObject(objAssemblyFeatureCutout)
            oReleaseObject(objAssemblyFeatureCutouts)
            oReleaseObject(objAssyDoc)
            oReleaseObject(objSEApp)
            Profiles = Nothing

        Catch ex As Exception
            MsgBox("error trimming frame component. error returned->" + ex.Message)
        End Try



        '******* Added because of .NET
        Try
            OleMessageFilter.Revoke()
        Catch ex As Exception
            'PrintLine("Error revoking the message filter.")
        End Try
        '******* Added because of .NET


        blnFrameSelected = False
        blnPlaneSelected = False
        blnTargetSelected = False
    End Sub

    Private Sub Button17_Click(sender As System.Object, e As System.EventArgs) Handles Button17.Click
        Me.ListBox1.Items.Clear()


        Dim objDoc As SolidEdgeDraft.DraftDocument = Nothing
        Dim objDimension1 As SolidEdgeFrameworkSupport.Dimension = Nothing
        Dim objDimension2 As SolidEdgeFrameworkSupport.Dimension = Nothing

        Dim UOM As SolidEdgeFramework.UnitsOfMeasure = Nothing
        Dim objLines2D As SolidEdgeFrameworkSupport.Lines2d = Nothing
        Dim objLine2D As SolidEdgeFrameworkSupport.Line2d = Nothing
        Dim objDimensions As SolidEdgeFrameworkSupport.Dimensions = Nothing
        Dim objDimension As SolidEdgeFrameworkSupport.Dimension = Nothing
        Dim objDrawingViews As SolidEdgeDraft.DrawingViews = Nothing
        Dim objDrawingView As SolidEdgeDraft.DrawingView = Nothing
        Dim Lines(19) As Object
        Dim ObjBoundaries2D As SolidEdgeFrameworkSupport.Boundaries2d = Nothing
        Dim objboundary2d As SolidEdgeFrameworkSupport.Boundary2d = Nothing
        Const igunitdistance = SolidEdgeConstants.UnitTypeConstants.igUnitDistance



        'Call a generic function used to add solid edge part
        If oConnectToSolidEdge(True, True) Then

            Try
                Do While objSEApp.Documents.Count <> 0
                    objSEApp.ActiveDocument.close(False)
                Loop
                objDoc = oCreateNewSEDocument(objSEApp, "draft")

                objDoc = TryCast(objDoc, SolidEdgeDraft.DraftDocument)

                UOM = objDoc.UnitsOfMeasure
                objLines2D = objDoc.ActiveSheet.Lines2d
                objDimensions = objDoc.ActiveSheet.Dimensions
                Lines(1) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 114.03), UOM.ParseUnit(igunitdistance, 107.49), _
                                                            UOM.ParseUnit(igunitdistance, 239.03), UOM.ParseUnit(igunitdistance, 107.49))
                Lines(2) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 114.03), UOM.ParseUnit(igunitdistance, 187.49), _
                                                            UOM.ParseUnit(igunitdistance, 114.03), UOM.ParseUnit(igunitdistance, 107.49))
                Lines(3) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 159.03), UOM.ParseUnit(igunitdistance, 187.49), _
                                                            UOM.ParseUnit(igunitdistance, 114.03), UOM.ParseUnit(igunitdistance, 187.49))
                Lines(4) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 159.03), UOM.ParseUnit(igunitdistance, 168.61), _
                                                            UOM.ParseUnit(igunitdistance, 159.03), UOM.ParseUnit(igunitdistance, 187.49))
                Lines(5) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 194.03), UOM.ParseUnit(igunitdistance, 168.61), _
                                                            UOM.ParseUnit(igunitdistance, 159.03), UOM.ParseUnit(igunitdistance, 168.61))
                Lines(6) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 194.03), UOM.ParseUnit(igunitdistance, 187.49), _
                                                            UOM.ParseUnit(igunitdistance, 194.03), UOM.ParseUnit(igunitdistance, 168.61))
                Lines(7) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 239.03), UOM.ParseUnit(igunitdistance, 187.49), _
                                                            UOM.ParseUnit(igunitdistance, 194.03), UOM.ParseUnit(igunitdistance, 187.49))
                Lines(8) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 239.03), UOM.ParseUnit(igunitdistance, 107.49), _
                                                            UOM.ParseUnit(igunitdistance, 239.03), UOM.ParseUnit(igunitdistance, 187.49))
                'Place dimensions on the drawing
                objDimension1 = objDimensions.AddLength(Lines(1))
                objDimension1.TrackDistance = -1 * MMtoM(10)  'flip to the other side
                oReleaseObject(objDimension1)

                objDimension1 = objDimensions.AddDistanceBetweenObjects(Lines(1), UOM.ParseUnit(igunitdistance, 114.03), UOM.ParseUnit(igunitdistance, 107.49), 0, True, _
                                                           Lines(3), UOM.ParseUnit(igunitdistance, 114.03), UOM.ParseUnit(igunitdistance, 187.49), 0, True)
                objDimension1.TrackDistance = MMtoM(30)
                oReleaseObject(objDimension1)


                objDimension1 = objDimensions.AddDistanceBetweenObjects(Lines(2), UOM.ParseUnit(igunitdistance, 114.03), UOM.ParseUnit(igunitdistance, 187.49), 0, True, _
                                                            Lines(4), UOM.ParseUnit(igunitdistance, 159.03), UOM.ParseUnit(igunitdistance, 187.49), 0, True)
                objDimension1.TrackDistance = MMtoM(10)
                oReleaseObject(objDimension1)

                objDimensions.AxisMode = SolidEdgeConstants.DimAxisModeConstants.igDimAxisModeExplicit
                objDimensions.Axis = Lines(2)
                objDimension1 = objDimensions.AddDistanceBetweenObjects(Lines(1), UOM.ParseUnit(igunitdistance, 114.03), UOM.ParseUnit(igunitdistance, 107.49), 0, True, _
                                                            Lines(5), UOM.ParseUnit(igunitdistance, 159.03), UOM.ParseUnit(igunitdistance, 168.61), 0, True)
                objDimension1.TrackDistance = -1 * MMtoM(15)
                oReleaseObject(objDimension1)




                objDimension1 = objDimensions.AddLength(Lines(5))
                oReleaseObject(objDimension1)

                objDimension1 = objDimensions.AddLength(Lines(7))
                objDimension1.TrackDistance = -1 * MMtoM(10)
                oReleaseObject(objDimension1)


                'CreateRightView

                Lines(15) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 326.26), UOM.ParseUnit(igunitdistance, 107.49), _
                                                            UOM.ParseUnit(igunitdistance, 426.26), UOM.ParseUnit(igunitdistance, 107.49))
                Lines(16) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 326.26), UOM.ParseUnit(igunitdistance, 187.49), _
                                                            UOM.ParseUnit(igunitdistance, 326.26), UOM.ParseUnit(igunitdistance, 107.49))
                Lines(17) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 426.26), UOM.ParseUnit(igunitdistance, 187.49), _
                                                            UOM.ParseUnit(igunitdistance, 326.26), UOM.ParseUnit(igunitdistance, 187.49))
                Lines(18) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 426.26), UOM.ParseUnit(igunitdistance, 107.49), _
                                                            UOM.ParseUnit(igunitdistance, 426.26), UOM.ParseUnit(igunitdistance, 187.49))
                Lines(19) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 326.26), UOM.ParseUnit(igunitdistance, 168.61), _
                                                            UOM.ParseUnit(igunitdistance, 426.26), UOM.ParseUnit(igunitdistance, 168.61))

                Lines(19).Style.LinearName = "Hidden"



                'CreateTopView
                Lines(9) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 114.03), UOM.ParseUnit(igunitdistance, 245.97), _
                                                              UOM.ParseUnit(igunitdistance, 239.03), UOM.ParseUnit(igunitdistance, 245.97))
                Lines(10) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 114.03), UOM.ParseUnit(igunitdistance, 345.97), _
                                                            UOM.ParseUnit(igunitdistance, 114.03), UOM.ParseUnit(igunitdistance, 245.97))
                Lines(11) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 239.03), UOM.ParseUnit(igunitdistance, 345.97), _
                                                            UOM.ParseUnit(igunitdistance, 114.03), UOM.ParseUnit(igunitdistance, 345.97))
                Lines(12) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 239.03), UOM.ParseUnit(igunitdistance, 245.97), _
                                                            UOM.ParseUnit(igunitdistance, 239.03), UOM.ParseUnit(igunitdistance, 345.97))
                Lines(13) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 194.03), UOM.ParseUnit(igunitdistance, 245.97), _
                                                            UOM.ParseUnit(igunitdistance, 194.03), UOM.ParseUnit(igunitdistance, 345.97))
                Lines(14) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 159.03), UOM.ParseUnit(igunitdistance, 245.97), _
                                                            UOM.ParseUnit(igunitdistance, 159.03), UOM.ParseUnit(igunitdistance, 345.97))

                objDimension1 = objDimensions.AddLength(Lines(10))
                objDimension1.TrackDistance = -1 * MMtoM(10)
                oReleaseObject(objDimension1)



                ' '' '' '' ''modify some parameters of each dimension
                '' ''For Each objDimension In objDimensions
                '' ''    objDimension.Style.Name = "ANSImm"
                '' ''    objDimension.TrackDistance = 0.0105
                '' ''    objDimension.BreakPosition = SolidEdgeConstants.DimBreakPositionConstants.igDimBreakCenter
                '' ''Next
                '' ''objDimension1.TrackDistance = -0.0105  'flip to the other side
                '' ''objDimension2.TrackDistance = -0.0105  'flip to the other side




            Catch ex As Exception
                MessageBox.Show("error add a new document " + ex.Message, "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)

            End Try

        Else
            MessageBox.Show("Could not connect to or start Solid Edge", "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
    End Sub

    Private Sub Button18_Click(sender As System.Object, e As System.EventArgs) Handles Button18.Click
        Me.ListBox1.Items.Clear()


        Dim objDoc As SolidEdgeDraft.DraftDocument = Nothing
        Dim objDimension1 As SolidEdgeFrameworkSupport.Dimension = Nothing
        Dim objDimension2 As SolidEdgeFrameworkSupport.Dimension = Nothing

        Dim UOM As SolidEdgeFramework.UnitsOfMeasure = Nothing
        Dim objLines2D As SolidEdgeFrameworkSupport.Lines2d = Nothing
        Dim objLine2D As SolidEdgeFrameworkSupport.Line2d = Nothing
        Dim objDimensions As SolidEdgeFrameworkSupport.Dimensions = Nothing
        Dim objDimension As SolidEdgeFrameworkSupport.Dimension = Nothing
        Dim objDrawingViews As SolidEdgeDraft.DrawingViews = Nothing
        Dim objDrawingView As SolidEdgeDraft.DrawingView = Nothing
        Dim Lines(19) As Object
        Dim ObjBoundaries2D As SolidEdgeFrameworkSupport.Boundaries2d = Nothing
        Dim objboundary2d As SolidEdgeFrameworkSupport.Boundary2d = Nothing
        Const igunitdistance = SolidEdgeConstants.UnitTypeConstants.igUnitDistance
        Dim objReference1 As SolidEdgeFramework.Reference = Nothing
        Dim objReference2 As SolidEdgeFramework.Reference = Nothing
        Dim objReference3 As SolidEdgeFramework.Reference = Nothing
        Dim X1, Y1, X2, Y2 As Double

        'Call a generic function used to add solid edge part
        If oConnectToSolidEdge(True, True) Then
            Lines(19) = Nothing
            Try
                Do While objSEApp.Documents.Count <> 0
                    objSEApp.ActiveDocument.close(False)
                Loop
                objDoc = oCreateNewSEDocument(objSEApp, "draft")
                objDoc = TryCast(objDoc, SolidEdgeDraft.DraftDocument)

                UOM = objDoc.UnitsOfMeasure
                objDrawingViews = objDoc.ActiveSheet.DrawingViews
                objDrawingView = objDrawingViews.AddDraftView(1, MMtoM(10), MMtoM(10))


                objLines2D = objDrawingView.Sheet.Lines2d
                objDimensions = objDoc.ActiveSheet.Dimensions
                Lines(1) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 114.03), UOM.ParseUnit(igunitdistance, 107.49), _
                                                            UOM.ParseUnit(igunitdistance, 239.03), UOM.ParseUnit(igunitdistance, 107.49))
                Lines(2) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 114.03), UOM.ParseUnit(igunitdistance, 187.49), _
                                                            UOM.ParseUnit(igunitdistance, 114.03), UOM.ParseUnit(igunitdistance, 107.49))
                Lines(3) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 159.03), UOM.ParseUnit(igunitdistance, 187.49), _
                                                            UOM.ParseUnit(igunitdistance, 114.03), UOM.ParseUnit(igunitdistance, 187.49))
                Lines(4) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 159.03), UOM.ParseUnit(igunitdistance, 168.61), _
                                                            UOM.ParseUnit(igunitdistance, 159.03), UOM.ParseUnit(igunitdistance, 187.49))
                Lines(5) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 194.03), UOM.ParseUnit(igunitdistance, 168.61), _
                                                            UOM.ParseUnit(igunitdistance, 159.03), UOM.ParseUnit(igunitdistance, 168.61))
                Lines(6) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 194.03), UOM.ParseUnit(igunitdistance, 187.49), _
                                                            UOM.ParseUnit(igunitdistance, 194.03), UOM.ParseUnit(igunitdistance, 168.61))
                Lines(7) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 239.03), UOM.ParseUnit(igunitdistance, 187.49), _
                                                            UOM.ParseUnit(igunitdistance, 194.03), UOM.ParseUnit(igunitdistance, 187.49))
                Lines(8) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 239.03), UOM.ParseUnit(igunitdistance, 107.49), _
                                                            UOM.ParseUnit(igunitdistance, 239.03), UOM.ParseUnit(igunitdistance, 187.49))

                objDrawingView.Crop = False

                'Place dimensions on the drawing
                objDrawingView.GetReferenceToGraphicMember(Lines(1), objReference1)   'since element is in the view MUST get reference to it



                objDimension1 = objDimensions.AddLength(objReference1)
                objDimension1.TrackDistance = -1 * MMtoM(10)  'flip to the other side
                oReleaseObject(objDimension1)
                objReference1 = Nothing


                objDrawingView.GetReferenceToGraphicMember(Lines(1), objReference1)   'since element is in the view MUST get reference to it
                objDrawingView.GetReferenceToGraphicMember(Lines(3), objReference2)   'since element is in the view MUST get reference to it

                objReference1.Object.getstartpoint(X1, Y1)
                objReference2.Object.getendpoint(X2, Y2)

                'objDimension1 = objDimensions.AddDistanceBetweenObjects(objReference1, UOM.ParseUnit(igunitdistance, 114.03), UOM.ParseUnit(igunitdistance, 107.49), 0, True, _
                '                                          objReference2, UOM.ParseUnit(igunitdistance, 114.03), UOM.ParseUnit(igunitdistance, 187.49), 0, True)
                objDimension1 = objDimensions.AddDistanceBetweenObjects(objReference1, X1, Y1, 0, True, _
                                                          objReference2, X2, Y2, 0, True)
                objDimension1.TrackDistance = MMtoM(30)
                oReleaseObject(objDimension1)
                objReference1 = Nothing
                objReference2 = Nothing
                

                objDrawingView.GetReferenceToGraphicMember(Lines(3), objReference1)   'since element is in the view MUST get reference to it
                objDimension1 = objDimensions.AddLength(objReference1)

                
                objDimension1.TrackDistance = -1 * MMtoM(10)  'flip to the other side
                oReleaseObject(objDimension1)
                objReference1 = Nothing
                objReference2 = Nothing


                objDrawingView.GetReferenceToGraphicMember(Lines(1), objReference1)   'since element is in the view MUST get reference to it
                objDrawingView.GetReferenceToGraphicMember(Lines(5), objReference2)   'since element is in the view MUST get reference to it


                objDimensions.AxisMode = SolidEdgeConstants.DimAxisModeConstants.igDimAxisModeExplicit
                objDrawingView.GetReferenceToGraphicMember(Lines(2), objReference3)   'since element is in the view MUST get reference to it
                objDimensions.Axis = objReference3
                objDimension1 = objDimensions.AddDistanceBetweenObjects(objReference1, UOM.ParseUnit(igunitdistance, 114.03), UOM.ParseUnit(igunitdistance, 107.49), 0, True, _
                                                            objReference2, UOM.ParseUnit(igunitdistance, 159.03), UOM.ParseUnit(igunitdistance, 168.61), 0, True)
                objDimension1.TrackDistance = -1 * MMtoM(15)
                oReleaseObject(objDimension1)
                objReference1 = Nothing
                objReference2 = Nothing
                objReference3 = Nothing


                objDrawingView.GetReferenceToGraphicMember(Lines(5), objReference1)   'since element is in the view MUST get reference to it
                objDimension1 = objDimensions.AddLength(objReference1)
                oReleaseObject(objDimension1)
                objReference1 = Nothing



                objDrawingView.GetReferenceToGraphicMember(Lines(7), objReference1)   'since element is in the view MUST get reference to it
                objDimension1 = objDimensions.AddLength(objReference1)
                objDimension1.TrackDistance = -1 * MMtoM(10)
                oReleaseObject(objDimension1)
                objReference1 = Nothing

                oForceGarbageCollection()


                'CreateRightView
                oReleaseObject(objLines2D)
                oReleaseObject(objDrawingView)
                oForceGarbageCollection()


                objDrawingView = objDrawingViews.AddDraftView(1, MMtoM(100), MMtoM(10))
                objLines2D = objDrawingView.Sheet.Lines2d

                Lines(15) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 326.26), UOM.ParseUnit(igunitdistance, 107.49), _
                                                            UOM.ParseUnit(igunitdistance, 426.26), UOM.ParseUnit(igunitdistance, 107.49))
                Lines(16) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 326.26), UOM.ParseUnit(igunitdistance, 187.49), _
                                                            UOM.ParseUnit(igunitdistance, 326.26), UOM.ParseUnit(igunitdistance, 107.49))
                Lines(17) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 426.26), UOM.ParseUnit(igunitdistance, 187.49), _
                                                            UOM.ParseUnit(igunitdistance, 326.26), UOM.ParseUnit(igunitdistance, 187.49))
                Lines(18) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 426.26), UOM.ParseUnit(igunitdistance, 107.49), _
                                                            UOM.ParseUnit(igunitdistance, 426.26), UOM.ParseUnit(igunitdistance, 187.49))
                Lines(19) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 326.26), UOM.ParseUnit(igunitdistance, 168.61), _
                                                            UOM.ParseUnit(igunitdistance, 426.26), UOM.ParseUnit(igunitdistance, 168.61))

                Lines(19).Style.LinearName = "Hidden"

                objDrawingView.Crop = True

                'CreateTopView

                oReleaseObject(objLines2D)
                oReleaseObject(objDrawingView)
                oForceGarbageCollection()


                objDrawingView = objDrawingViews.AddDraftView(1, MMtoM(10), MMtoM(50))
                objLines2D = objDrawingView.Sheet.Lines2d
                Lines(9) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 114.03), UOM.ParseUnit(igunitdistance, 245.97), _
                                                              UOM.ParseUnit(igunitdistance, 239.03), UOM.ParseUnit(igunitdistance, 245.97))
                Lines(10) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 114.03), UOM.ParseUnit(igunitdistance, 345.97), _
                                                            UOM.ParseUnit(igunitdistance, 114.03), UOM.ParseUnit(igunitdistance, 245.97))
                Lines(11) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 239.03), UOM.ParseUnit(igunitdistance, 345.97), _
                                                            UOM.ParseUnit(igunitdistance, 114.03), UOM.ParseUnit(igunitdistance, 345.97))
                Lines(12) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 239.03), UOM.ParseUnit(igunitdistance, 245.97), _
                                                            UOM.ParseUnit(igunitdistance, 239.03), UOM.ParseUnit(igunitdistance, 345.97))
                Lines(13) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 194.03), UOM.ParseUnit(igunitdistance, 245.97), _
                                                            UOM.ParseUnit(igunitdistance, 194.03), UOM.ParseUnit(igunitdistance, 345.97))
                Lines(14) = objLines2D.AddBy2Points(UOM.ParseUnit(igunitdistance, 159.03), UOM.ParseUnit(igunitdistance, 245.97), _
                                                            UOM.ParseUnit(igunitdistance, 159.03), UOM.ParseUnit(igunitdistance, 345.97))
                objDrawingView.GetReferenceToGraphicMember(Lines(10), objReference1)   'since element is in the view MUST get reference to it

                objDimension1 = objDimensions.AddLength(objReference1)
                objDimension1.TrackDistance = -1 * MMtoM(10)
                oReleaseObject(objDimension1)
                oReleaseObject(objReference1)
                oReleaseObject(objLines2D)
                oReleaseObject(objDrawingView)
                oReleaseObject(objDrawingViews)

                ' '' '' '' ''modify some parameters of each dimension
                '' ''For Each objDimension In objDimensions
                '' ''    objDimension.Style.Name = "ANSImm"
                '' ''    objDimension.TrackDistance = 0.0105
                '' ''    objDimension.BreakPosition = SolidEdgeConstants.DimBreakPositionConstants.igDimBreakCenter
                '' ''Next
                '' ''objDimension1.TrackDistance = -0.0105  'flip to the other side
                '' ''objDimension2.TrackDistance = -0.0105  'flip to the other side




            Catch ex As Exception
                MessageBox.Show("error add a new document " + ex.Message, "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)

            End Try

        Else
            MessageBox.Show("Could not connect to or start Solid Edge", "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
    End Sub

    Private Sub Button19_Click(sender As System.Object, e As System.EventArgs) Handles Button19.Click
        Dim ObjDoc As SolidEdgeDraft.DraftDocument = Nothing
        Dim UOM As SolidEdgeFramework.UnitsOfMeasure = Nothing
        Dim objDrawingViews As SolidEdgeDraft.DrawingViews = Nothing
        Dim objFrontDrawingView As SolidEdgeDraft.DrawingView = Nothing
        Dim objISOView As SolidEdgeDraft.DrawingView = Nothing
        Dim objTopView As SolidEdgeDraft.DrawingView = Nothing
        Dim objModelLinks As SolidEdgeDraft.ModelLinks = Nothing
        Dim objModelLink As SolidEdgeDraft.ModelLink = Nothing
        Dim objDimensions As SolidEdgeFrameworkSupport.Dimensions = Nothing
        Dim objDimension As SolidEdgeFrameworkSupport.Dimension = Nothing
        Dim objReference As SolidEdgeFramework.Reference = Nothing
        Dim objPartsLists As SolidEdgeDraft.PartsLists = Nothing
        Dim objPartsList As SolidEdgeDraft.PartsList = Nothing
        Dim objBalloons As SolidEdgeFrameworkSupport.Balloons = Nothing
        Dim objBalloon As SolidEdgeFrameworkSupport.Balloon = Nothing
        Dim dblVertices1(2) As Double
        Dim ObjNewSheet As SolidEdgeDraft.Sheet = Nothing
        Dim strFilename As String = String.Empty


        'Call a generic function used to add solid edge part
        If oConnectToSolidEdge(True, True) Then

            Try
                Do While objSEApp.Documents.Count <> 0
                    objSEApp.ActiveDocument.close(False)
                Loop
                ObjDoc = oCreateNewSEDocument(objSEApp, "draft")

                strFilename = "C:\_Work\Events\Dev Day SE University 2012\Test Files\CDPlayer\BodyComponents\BodyBottom.par"
                UOM = ObjDoc.UnitsOfMeasure
                objModelLinks = ObjDoc.ModelLinks
                objModelLink = objModelLinks.Add(strFilename)   ' creates the link to the 3d file that the drawing view will be derived
                objDrawingViews = ObjDoc.ActiveSheet.DrawingViews
                objDimensions = ObjDoc.ActiveSheet.Dimensions
                'Add front View of Model
                objFrontDrawingView = objDrawingViews.Add(objModelLink, SolidEdgeConstants.ViewOrientationConstants.igFrontView, 0.75, _
                                            UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 182), _
                                            UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 120))
                'Add left view of model
                objDrawingViews.AddByFold(objFrontDrawingView, SolidEdgeConstants.ViewOrientationConstants.igLeftView, _
                                                UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 450), _
                                                UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 120))
                'Add Top view of model
                objTopView = objDrawingViews.AddByFold(objFrontDrawingView, SolidEdgeConstants.ViewOrientationConstants.igTopView, _
                                                UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 182), _
                                                UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 270))

                'add a detail view
                objDrawingViews.AddDetailView(objFrontDrawingView, UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 182), UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 140), _
                                                        UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 30), 1.5, UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 75), _
                                                        UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 75), False)
               



                'Create Sheet 2
                ObjNewSheet = ObjDoc.Sheets.Add("Sheet2")
                ObjNewSheet.Activate()
                objDrawingViews = ObjDoc.ActiveSheet.DrawingViews
                strFilename = "C:\_Work\Events\Dev Day SE University 2012\Test Files\CDPlayer\CDPlayer.asm"
                objModelLink = objModelLinks.Add(strFilename)   ' creates the link to the 3d file that the drawing view will be derived
                objISOView = objDrawingViews.AddAssemblyView(objModelLink, SolidEdgeDraft.ViewOrientationConstants.igTopFrontRightView, 0.75, UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 400), _
                UOM.ParseUnit(SolidEdgeFramework.UnitTypeConstants.igUnitDistance, 250), SolidEdgeDraft.AssemblyDrawingViewTypeConstants.seAssemblyDesignedView)


                objPartsLists = ObjDoc.PartsLists
                objPartsLists.Add(objISOView, "Default", 1, 1)

                objPartsLists.Item(1).AnchorPoint = SolidEdgeDraft.TableAnchorPoint.igLowerLeft








            Catch ex As Exception
                MessageBox.Show("error add a new document " + ex.Message, "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)

            End Try

        Else
            MessageBox.Show("Could not connect to or start Solid Edge", "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If



    End Sub

    Private Sub Button20_Click(sender As System.Object, e As System.EventArgs) Handles Button20.Click
        Me.ListBox1.Items.Clear()


        Dim ObjDoc As SolidEdgeFramework.SolidEdgeDocument = Nothing
        Dim objPartDoc As SolidEdgePart.PartDocument = Nothing
        Dim objdims As SolidEdgeFrameworkSupport.Dimensions = Nothing
        Dim objDim As SolidEdgeFrameworkSupport.Dimension = Nothing
        Dim objOrigDim As SolidEdgeFrameworkSupport.Dimension = Nothing
        Dim objPMI As SolidEdgeFrameworkSupport.PMI = Nothing
        Dim objEdges As SolidEdgeGeometry.Edges = Nothing
        Dim objEdge1 As SolidEdgeGeometry.Edge = Nothing
        Dim objEdge2 As SolidEdgeGeometry.Edge = Nothing
        Dim objEdge3 As SolidEdgeGeometry.Edge = Nothing
        Dim objRefEdge As SolidEdgeGeometry.Edge = Nothing
        Dim objRefEdge1 As SolidEdgeGeometry.Edge = Nothing
        Dim objLinearEdge1 As SolidEdgeGeometry.Edge = Nothing
        Dim objLinearEdge2 As SolidEdgeGeometry.Edge = Nothing
        Dim objDimPlane As SolidEdgePart.RefPlane = Nothing
        Dim objDimInitData As SolidEdgeFrameworkSupport.DimInitData = Nothing

        Dim lngCnt As Long
        Dim posX As Double
        Dim posY As Double
        Dim posZ As Double
        Dim dblStartPoint1(0) As Double
        Dim dblEndPoint1(0) As Double
        Dim dblStartPoint2(0) As Double
        Dim dblEndPoint2(0) As Double
        Dim dblStartPoint3(0) As Double
        Dim dblEndPoint3(0) As Double



        Dim strFilename As String = String.Empty

        'Call a generic function used to connect to exist SE application or if not create a new instance of Solid Edge 
        If oConnectToSolidEdge(True, True) Then
            Try
                strFilename = "C:\_Work\Events\Dev Day SE University 2012\Test Files\CreateDimensionPMI.par"
                If oIsValidFileName(strFilename) AndAlso oIsSolidEdgeFile(strFilename) Then
                    ObjDoc = objSEApp.Documents.Open(strFilename)
                    objPartDoc = TryCast(ObjDoc, SolidEdgePart.PartDocument)
                End If


                'Get the PMI object from the document
                Call objPartDoc.PMI_ByModelState(PMIObj:=objPMI)

                'Get the dimensions collection from the PMI object
                objdims = objPMI.Dimensions

                objEdges = ObjDoc.Models.Item(1).ExtrudedProtrusions.Item(1).Edges(SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll)
                If Not objEdges Is Nothing Then
                    objEdge1 = objEdges.Item(1)
                End If

                objEdges = ObjDoc.Models.Item(1).ExtrudedProtrusions.Item(2).Edges(SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll)
                If Not objEdges Is Nothing Then
                    objEdge2 = objEdges.Item(1)
                End If

                objEdges = ObjDoc.Models.Item(1).ExtrudedProtrusions.Item(3).Edges(SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll)
                If Not objEdges Is Nothing Then
                    objEdge3 = objEdges.Item(1)
                End If

                objEdges = ObjDoc.Models.Item(1).ExtrudedProtrusions.Item(4).Edges(SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll)
                If Not objEdges Is Nothing Then
                    objLinearEdge1 = objEdges.Item(1)
                    objLinearEdge2 = objEdges.Item(2)
                End If

                objEdges = ObjDoc.Models.Item(1).ExtrudedProtrusions.Item(5).Edges(SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll)
                If Not objEdges Is Nothing Then
                    objRefEdge = objEdges.Item(1)
                End If

                objEdges = ObjDoc.Models.Item(1).ExtrudedProtrusions.Item(6).Edges(SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll)
                If Not objEdges Is Nothing Then
                    objRefEdge1 = objEdges.Item(1)
                End If

                objDimPlane = ObjDoc.RefPlanes.Item(3)

                objDimInitData = objdims.DimInitData

                'igDimTypeRadial
                Call objDimInitData.ClearParents()
                Call objDimInitData.SetType(SolidEdgeFrameworkSupport.DimTypeConstants.igDimTypeRadial)
                Call objDimInitData.SetAxisMode(SolidEdgeFrameworkSupport.DimAxisModeConstants.igDimAxisModeDefault)
                Call objDimInitData.SetPlane(objDimPlane)
                Call objDimInitData.SetNumberOfParents(1)
                Call objEdge1.GetEndPoints(StartPoint:=dblStartPoint1, EndPoint:=dblEndPoint1)
                Call objDimInitData.SetParentByIndex(0, objEdge1, False, False, False, True, dblStartPoint1(0), dblStartPoint1(1), dblStartPoint1(2))
                objDim = objdims.AddDimension(DimInitData:=objDimInitData)

                'igDimTypeRDiameter
                Call objDimInitData.ClearParents()
                Call objDimInitData.SetType(SolidEdgeFrameworkSupport.DimTypeConstants.igDimTypeRDiameter)
                Call objDimInitData.SetAxisMode(SolidEdgeFrameworkSupport.DimAxisModeConstants.igDimAxisModeDefault)
                Call objDimInitData.SetPlane(objDimPlane)
                Call objDimInitData.SetNumberOfParents(1)
                Call objEdge2.GetEndPoints(StartPoint:=dblStartPoint2, EndPoint:=dblEndPoint2)
                Call objDimInitData.SetParentByIndex(0, objEdge2, False, False, False, False, dblStartPoint2(0), dblStartPoint2(1), dblStartPoint2(2))
                objDim = objdims.AddDimension(DimInitData:=objDimInitData)

                'igDimTypeCDiameter
                Call objDimInitData.ClearParents()
                Call objDimInitData.SetType(SolidEdgeFrameworkSupport.DimTypeConstants.igDimTypeCDiameter)
                Call objDimInitData.SetAxisMode(SolidEdgeFrameworkSupport.DimAxisModeConstants.igDimAxisModeDefault)
                Call objDimInitData.SetPlane(objDimPlane)
                Call objDimInitData.SetNumberOfParents(1)
                Call objEdge3.GetEndPoints(StartPoint:=dblStartPoint3, EndPoint:=dblEndPoint3)
                Call objDimInitData.SetParentByIndex(0, objEdge3, False, False, False, False, dblStartPoint3(0), dblStartPoint3(1), dblStartPoint3(2))
                objDim = objdims.AddDimension(DimInitData:=objDimInitData)

                'linear distance between
                Call objDimInitData.ClearParents()
                Call objDimInitData.SetType(SolidEdgeFrameworkSupport.DimTypeConstants.igDimTypeLinear)
                Call objDimInitData.SetAxisMode(SolidEdgeFrameworkSupport.DimAxisModeConstants.igDimAxisModeDefault)
                Call objDimInitData.SetPlane(objDimPlane)
                Call objDimInitData.SetNumberOfParents(2)
                Call objLinearEdge1.GetEndPoints(StartPoint:=dblStartPoint1, EndPoint:=dblEndPoint1)
                Call objLinearEdge2.GetEndPoints(StartPoint:=dblStartPoint2, EndPoint:=dblEndPoint2)
                Call objDimInitData.SetParentByIndex(0, objLinearEdge1, True, False, False, False, dblStartPoint1(0), dblStartPoint1(1), dblStartPoint1(2))
                Call objDimInitData.SetParentByIndex(1, objLinearEdge2, True, False, False, False, dblStartPoint2(0), dblStartPoint2(1), dblStartPoint2(2))
                objDim = objdims.AddDimension(DimInitData:=objDimInitData)

                'Create a symmetric diameter dimension
                Call objDimInitData.ClearParents()
                Call objDimInitData.SetType(SolidEdgeFrameworkSupport.DimTypeConstants.igDimTypeSDiameter)
                Call objDimInitData.SetAxisMode(SolidEdgeFrameworkSupport.DimAxisModeConstants.igDimAxisModeDefault)
                Call objDimInitData.SetNumberOfParents(2)
                Call objDimInitData.SetPlane(objDimPlane)
                Call objEdge1.GetEndPoints(StartPoint:=dblStartPoint1, EndPoint:=dblEndPoint1)
                Call objEdge3.GetEndPoints(StartPoint:=dblStartPoint3, EndPoint:=dblEndPoint3)
                Call objDimInitData.SetParentByIndex(0, objEdge1, True, False, False, True, dblStartPoint1(0), dblStartPoint1(1), dblStartPoint1(2))
                Call objDimInitData.SetParentByIndex(1, objEdge3, True, False, False, False, dblStartPoint3(0), dblStartPoint3(1), dblStartPoint3(2))
                objDim = objdims.AddDimension(DimInitData:=objDimInitData)

                'Angle between lines dimension
                Call objDimInitData.ClearParents()
                Call objDimInitData.SetType(SolidEdgeFrameworkSupport.DimTypeConstants.igDimTypeAngular)
                Call objDimInitData.SetNumberOfParents(2)
                Call objDimInitData.SetPlane(objDimPlane)
                Call objLinearEdge1.GetEndPoints(StartPoint:=dblStartPoint1, EndPoint:=dblEndPoint1)
                Call objLinearEdge2.GetEndPoints(StartPoint:=dblStartPoint2, EndPoint:=dblEndPoint2)
                Call objDimInitData.SetParentByIndex(0, objLinearEdge1, False, False, False, False, dblStartPoint1(0), dblStartPoint1(1), dblStartPoint1(2))
                Call objDimInitData.SetParentByIndex(1, objLinearEdge2, False, False, False, False, dblStartPoint2(0), dblStartPoint2(1), dblStartPoint2(2))
                objDim = objdims.AddDimension(DimInitData:=objDimInitData)

                'line angle dim
                Call objDimInitData.ClearParents()
                Call objDimInitData.SetType(SolidEdgeFrameworkSupport.DimTypeConstants.igDimTypeAngular)
                Call objDimInitData.SetAxisMode(SolidEdgeFrameworkSupport.DimAxisModeConstants.igDimAxisModeDefault)
                Call objDimInitData.SetNumberOfParents(1)
                Call objLinearEdge2.GetEndPoints(StartPoint:=dblStartPoint2, EndPoint:=dblEndPoint2)
                Call objDimInitData.SetPlane(objDimPlane)
                Call objDimInitData.SetParentByIndex(0, objLinearEdge2, True, False, False, False, dblStartPoint2(0), dblStartPoint2(1), dblStartPoint2(2))
                objDim = objdims.AddDimension(DimInitData:=objDimInitData)

                'angular between 3 points
                Call objDimInitData.ClearParents()
                Call objDimInitData.SetType(SolidEdgeFrameworkSupport.DimTypeConstants.igDimTypeAngular)
                Call objDimInitData.SetAxisMode(SolidEdgeFrameworkSupport.DimAxisModeConstants.igDimAxisModeDefault)
                Call objDimInitData.SetNumberOfParents(3)
                Call objDimInitData.SetPlane(objDimPlane)
                Call objEdge1.GetEndPoints(StartPoint:=dblStartPoint1, EndPoint:=dblEndPoint1)
                Call objEdge2.GetEndPoints(StartPoint:=dblStartPoint2, EndPoint:=dblEndPoint2)
                Call objEdge3.GetEndPoints(StartPoint:=dblStartPoint3, EndPoint:=dblEndPoint3)
                Call objDimInitData.SetParentByIndex(0, objEdge1, True, False, False, True, dblStartPoint1(0), dblStartPoint1(1), dblStartPoint1(2))
                Call objDimInitData.SetParentByIndex(1, objEdge2, True, False, False, True, dblStartPoint2(0), dblStartPoint2(1), dblStartPoint2(2))
                Call objDimInitData.SetParentByIndex(2, objEdge3, True, False, False, True, dblStartPoint3(0), dblStartPoint3(1), dblStartPoint3(2))
                objDim = objdims.AddDimension(DimInitData:=objDimInitData)

                'coordinate origin
                Call objDimInitData.ClearParents()
                Call objDimInitData.SetType(SolidEdgeFrameworkSupport.DimTypeConstants.igDimTypeCoordinate)
                Call objDimInitData.SetAxisMode(SolidEdgeFrameworkSupport.DimAxisModeConstants.igDimAxisModeDefault)
                Call objDimInitData.SetNumberOfParents(1)
                Call objDimInitData.SetPlane(objDimPlane)
                Call objEdge3.GetEndPoints(StartPoint:=dblStartPoint3, EndPoint:=dblEndPoint3)
                Call objDimInitData.SetParentByIndex(0, objEdge3, True, False, False, True, dblStartPoint3(0), dblStartPoint3(1), dblStartPoint3(2))
                Call objDimInitData.SetDimPositionMode(True)
                Call objEdge1.GetEndPoints(StartPoint:=dblStartPoint1, EndPoint:=dblEndPoint1)
                Call objDimInitData.SetDimPosition(dblStartPoint1(0), dblStartPoint1(1), dblStartPoint1(2))
                objOrigDim = objdims.AddDimension(DimInitData:=objDimInitData)

                'coordinate 2nd dim
                Call objDimInitData.ClearParents()
                Call objDimInitData.SetType(SolidEdgeFrameworkSupport.DimTypeConstants.igDimTypeCoordinate)
                Call objDimInitData.SetAxisMode(SolidEdgeFrameworkSupport.DimAxisModeConstants.igDimAxisModeDefault)
                Call objDimInitData.SetNumberOfParents(2)
                Call objDimInitData.SetDimPositionMode(False)
                Call objDimInitData.SetPlane(objDimPlane)
                Call objEdge2.GetEndPoints(StartPoint:=dblStartPoint2, EndPoint:=dblEndPoint2)
                Call objDimInitData.SetParentByIndex(0, objOrigDim, True, False, False, False, posX, posY, 0.0#)
                Call objDimInitData.SetParentByIndex(1, objEdge2, True, False, False, True, dblStartPoint2(0), dblStartPoint2(1), dblStartPoint2(2))
                Call objDimInitData.SetDimPositionMode(True)
                Call objEdge1.GetEndPoints(StartPoint:=dblStartPoint1, EndPoint:=dblEndPoint1)
                Call objDimInitData.SetDimPosition(dblStartPoint1(0), dblStartPoint1(1), dblStartPoint1(2))
                objDim = objdims.AddDimension(DimInitData:=objDimInitData)

                'angular coordinate origin
                Call objDimInitData.ClearParents()
                Call objDimInitData.SetType(SolidEdgeFrameworkSupport.DimTypeConstants.igDimTypeAngularCoordinate)
                Call objDimInitData.SetAxisMode(SolidEdgeFrameworkSupport.DimAxisModeConstants.igDimAxisModeDefault)
                Call objDimInitData.SetNumberOfParents(2)
                Call objDimInitData.SetPlane(objDimPlane)
                Call objEdge1.GetEndPoints(StartPoint:=dblStartPoint1, EndPoint:=dblEndPoint1)
                Call objEdge3.GetEndPoints(StartPoint:=dblStartPoint3, EndPoint:=dblEndPoint3)
                Call objDimInitData.SetAngularCoordOrigin(True)
                Call objDimInitData.SetDimPositionMode(True)
                Call objDimInitData.SetParentByIndex(0, objEdge3, True, False, False, True, dblStartPoint3(0), dblStartPoint3(1), dblStartPoint3(2))
                Call objDimInitData.SetParentByIndex(1, objEdge1, True, False, False, True, dblStartPoint1(0), dblStartPoint1(1), dblStartPoint1(2))
                Call objRefEdge.GetEndPoints(StartPoint:=dblStartPoint2, EndPoint:=dblEndPoint2)
                Call objDimInitData.SetDimPosition(dblStartPoint2(0), dblStartPoint2(1), dblStartPoint2(2))
                objOrigDim = objdims.AddDimension(DimInitData:=objDimInitData)

                'angular coordinate 2nd dim
                Call objDimInitData.ClearParents()
                Call objDimInitData.SetType(SolidEdgeFrameworkSupport.DimTypeConstants.igDimTypeAngularCoordinate)
                Call objDimInitData.SetAxisMode(SolidEdgeFrameworkSupport.DimAxisModeConstants.igDimAxisModeDefault)
                Call objDimInitData.SetNumberOfParents(2)
                Call objDimInitData.SetPlane(objDimPlane)
                Call objEdge2.GetEndPoints(StartPoint:=dblStartPoint2, EndPoint:=dblEndPoint2)
                Call objDimInitData.SetParentByIndex(0, objOrigDim, True, False, False, True, dblStartPoint2(0), dblStartPoint2(1), dblStartPoint2(2))
                Call objDimInitData.SetParentByIndex(1, objEdge2, True, False, False, True, dblStartPoint2(0), dblStartPoint2(1), dblStartPoint2(2))
                Call objDimInitData.SetAngularCoordOrigin(False)
                Call objDimInitData.SetDimPositionMode(True)
                Call objRefEdge1.GetEndPoints(StartPoint:=dblStartPoint2, EndPoint:=dblEndPoint2)
                Call objDimInitData.SetDimPosition(dblStartPoint2(0), dblStartPoint2(1), dblStartPoint2(2))
                objDim = objdims.AddDimension(DimInitData:=objDimInitData)






            Catch ex As Exception
                MessageBox.Show("error " + ex.Message, "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try


        Else
            MessageBox.Show("Could not connect to or start Solid Edge", "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
    End Sub

    Private Sub Button21_Click(sender As System.Object, e As System.EventArgs) Handles Button21.Click


        Me.ListBox1.Items.Clear()



        Dim objDraftDoc As SolidEdgeDraft.DraftDocument = Nothing
        Dim objPartDoc As SolidEdgePart.PartDocument
        Dim objSheet As SolidEdgeDraft.Sheet
        Dim objDrawingViews As SolidEdgeDraft.DrawingViews
        Dim objDrawingView As SolidEdgeDraft.DrawingView
        Dim objGraphicMembers As SolidEdgeDraft.GraphicMembers
        Dim objGraphicMember As Object
        Dim objEdge As Object
        Dim strFilename As Object

        Dim strPartFileName As String = ""
        Dim nDraftBytes As Integer
        Dim bDraftArray As System.Array = System.Array.CreateInstance(GetType(System.Byte), 64)

        Dim nPartBytes As Integer
        Dim bPartArray As System.Array = System.Array.CreateInstance(GetType(System.Byte), 64)
        Dim DraftFileName As String
        Dim nCount As Long

        'Call a generic function used to connect to exist SE application or if not create a new instance of Solid Edge 
        If oConnectToSolidEdge(True, True) Then
            Try
                strFilename = "C:\_Work\Events\Dev Day SE University 2012\Test Files\PartWithAttrubutes.dft"
                If oIsValidFileName(strFilename) AndAlso oIsSolidEdgeFile(strFilename) Then
                    objDraftDoc = objSEApp.Documents.Open(strFilename)
                End If



                objCmd = objSEApp.CreateCommand(SolidEdgeConstants.seCmdFlag.seNoDeactivate)
                objCmd.Start()
                objMouse = objCmd.Mouse
                objMouse.ScaleMode = 1
                objMouse.WindowTypes = 1
                objMouse.DynamicsMode = 1
                objMouse.EnabledMove = True

                objMouse.ClearLocateFilter()
                objMouse.AddToLocateFilter(SolidEdgeConstants.seLocateFilterConstants.seLocateDVLine2d)
                objMouse.InterDocumentLocate = True
                objMouse.LocateMode = SolidEdgeConstants.seLocateModes.seLocateQuickPick
                objSEApp.StatusBar = "Select Drawing view lines."



                ' '' '' '' ''we were were not using mouse to select the DV lines!
                ' '' '' '' ''getting the Active Sheet object
                '' '' '' ''objSheet = objDraftDoc.ActiveSheet

                ' '' '' '' ''get the drawing view
                '' '' '' ''objDrawingViews = objSheet.DrawingViews
                '' '' '' ''objDrawingView = objDrawingViews.Item(1)

                ' '' '' '' ''get the DVLine2d and the reference
                '' '' '' ''objGraphicMembers = objDrawingView.GraphicMembers
                '' '' '' ''objGraphicMember = objGraphicMembers.Item(1)

                '' '' '' ''objGraphicMember.GetReferenceKey(strPartFileName, bDraftArray, nDraftBytes)

                '' '' '' ''objPartDoc = objSEApp.Documents.Open(strPartFileName)
                '' '' '' ''Call objPartDoc.BindKeyToObject(bDraftArray, objEdge)
                '' '' '' ''Call objEdge.GetReferenceKey(Referencekey:=bPartArray)


                '' '' '' ''Dim objattachedPropertyTable As SolidEdgePart.AttachedPropertyTable = Nothing
                '' '' '' ''objattachedPropertyTable = objPartDoc.QueryByEntity(objEdge).item(1)
                '' '' '' ''Dim StrPlacedOnTheEdgeOfTheModelInPart As String = objattachedPropertyTable.AttachedProperties.Item(1).Value
                '' '' '' ''objPartDoc.Close(False)


                '' '' '' ''Dim objBalloons As SolidEdgeFrameworkSupport.Balloons = Nothing
                '' '' '' ''Dim objBalloon1 As SolidEdgeFrameworkSupport.Balloon = Nothing

                '' '' '' ''objBalloons = objDraftDoc.ActiveSheet.Balloons
                '' '' '' ''objBalloon1=objBalloons.AddByTerminator(






            Catch ex As Exception
                MessageBox.Show("error " + ex.Message, "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try


        Else
            MessageBox.Show("Could not connect to or start Solid Edge", "Solid Edge University 2012", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If








        

    End Sub
End Class
